Question

How to have quotation marks in HTML input values

I have the following problem - from the server side I get a string like 'hoschi"brother'.

I want to put this string into a <input value"MYSTRING" />. This results in something like <input value"hoschi" brother" /> which obviously does not work.

Is there a workarounds for this?

Does escaping the " character with &quot; work within the value tag?

 45  98202  45
1 Jan 1970

Solution

 81

Yes, using &quot; works:

<input type="text" name="last_name" value="&quot;My quote!&quot;" />
2009-10-20

Solution

 16

does escaping the " character with &quot; work within the value tag?

Yes. (This isn't a workaround though. It is how HTML is designed to work.)

Alternatively, if the value contains only single quotes or only double quotes, then you can use the other to delimit the attribute instead.

2009-10-20