tags:

views:

70

answers:

2

i want show 12"3 in my input tag value

i write this:

<INPUT TYPE="text" NAME="" value="12\"3">

but it's not be right

WHY ?

PS: i must transfer " to &quot; ,or change " to '? i don't like it

+8  A: 

HTML simply does not have escape sequences like other languages. In HTML attribute values the only special characters are <, & and depending on the quotes " or '. And the only to use these characters are character references:

Some authors use the character entity reference "&quot;" to encode instances of the double quote mark (") since that character may be used to delimit attribute values.

Or you use single quotes, then you don’t need to encode the double quotes and vice versa:

<INPUT TYPE="text" NAME="" value='12"3'>
Gumbo
but this solution can't type `'` in tag value
Zenofo
@Zenofo: If you want to use both single and double quotes in the same attribute value, then you need to represent one of these characters with a character reference: `"'""` or `'"''`.
Gumbo
@Zenofo Of course it can, you just need to use the HTML entity `'` or `'`.
Reinis I.
yes,you are right,it's only way, thank you
Zenofo
@Reinis I.: `'` is not defined in HTML; it was introduced in XML 1.0.
Gumbo
The only XHTML correct way is to use the entities, `"` and `'`
slomojo
@slomojo: Numeric character references can be used as well. In fact, the entities *apos* and *quot* do themselves just refer to the respective numeric character reference: `<!ENTITY apos "'">` `<!ENTITY quot """>`.
Gumbo
@Gumbo that's correct they equate to the same thing. I intended my comment to read... "The only XHTML correct way is to use the entities" ... and provided the symbolic entities for reference.
slomojo
@slomojo: But `'` and `'` are not entities; they are character references. *apos* and *quot* are entities that can be referenced with the corresponding entity references `'` and `"`.
Gumbo
@Gumbo, I know, I was just being simplistic.
slomojo
+4  A: 

WHY ?

Because \ is not special in HTML. It does not escape stuff. You must use &quot; or '.

 <input type="text" name="somename" value='12"3' />
 <input type="text" name="somename2" value="12&quot;3" />
KennyTM