Forum Moderators: open

Message Too Old, No Replies

single and double quotes

why not double?

         

txbakers

3:43 pm on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Single quotes I have figured out. I'm still stumped by double quotes.

When I enter a string in the database as follows:

this is a "test"

it becomes part of the SQL as

'this is a "test"'

and enters the DB just fine. When I build a drop down list with that value, it shows up with the double quotes.

However, when I select it, and try to display that in a text box, all I see is:

this is a

WHY?

txbakers

3:55 pm on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The answer is really quite obvious when you view the source.

The "test" portion of the text is indeed in the source, but the HTML tag double quote blocks it from showing.

<input type="text" value="this is a "test"">

the double quote effectively ends the value attribute.

So, this works instead:
<input type="text" value='this is a "test"'>

Silly Rabbit - kicks are for trids.

mattglet

4:21 pm on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a function called TextToInput() that I call when diplaying info like that.

Function TextToInput(strInput)
TextToInputValue = Replace(strInput, """", "&quot;")
End Function

i.e.

<input type = "text" name = "something" value = "<%=TextToInput(strMyVar)%>">

Granted, this is for classic ASP, but the idea can be ported elsewhere.

TheNige

8:30 pm on Jun 15, 2005 (gmt 0)

10+ Year Member



You can also "double" the double quotes I think.

<input type=text value="this is a ""test""">

coopster

2:21 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't think that is going to work, for the same reason txbakers described earlier. Here is the old spec on the subject ...

[w3.org...]

txbakers

4:19 am on Jun 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in straight VB I could use the double-double quote, but not in the w3c HTML.

I'm not happy with the fix (using single quotes to enclose the value attribute) but it works for now.

I like matt's approach better - to escape the value.

Come to think of it, would escape(dbValue) work?

mattglet

10:42 am on Jun 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, good call with the Escape(). I would have to say it works (without trying it). Validation doesn't choke with hex characters does it?