2

How can I include double quotes in an HTML page's input's value?

Eg: <input name="locations[]" value="["SFO","SJO","LA"]">

I need double quotes there, because this is a json array. But it wont work. Changing it to ' causes errors in the json.

I'm using <!DOCTYPE html>. Can this be done somehow?

jmenezes
  • 1,888
  • 6
  • 28
  • 44

2 Answers2

4

You need to encode the value using html entities.

HTML Entity for " is &quot;

So, in your case, the result would look like this:

<input name="locations[]" value="[&quot;SFO&quot;,&quot;SJO&quot;,&quot;LA&quot;]">

poncha
  • 7,726
  • 2
  • 34
  • 38
2

You may try this:

<input name="locations[]" value="[&quot;SFO&quot;,&quot;SJO&quot;,&quot;LA&quot;]">

&quot; is processed as &#34; which is ISO 8859-1 equivalent of ". You may also refer this

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331