Quotes 2

S

scott

Below in GOOD CODE, I have a mix of ASP/HTML that works. I'm trying to
convert the code into all ASP, but I'm failing in BAD CODE. Can someone help
me with these quotes? The single quotes are very hard to master.


BAD CODE:

sHTML=sHTML & "bgcolor=" & tblcolor & style=""cursor:default;""
onMouseOver="this.bgColor=""'#e6e6e6'"" onMouseOut="this.bgColor='" &
tblcolor & "'"

GOOD CODE:

<%
If sPageType = "forum" Then %>

bgcolor="<%= tblcolor %>" style="cursor:default;"
onMouseOver="this.bgColor='#e6e6e6'" onMouseOut="this.bgColor='<%= tblcolor
%>'"

<% End If %>>
 
B

Bob Barrows [MVP]

scott said:
Below in GOOD CODE, I have a mix of ASP/HTML that works. I'm trying to
convert the code into all ASP, but I'm failing in BAD CODE. Can
someone help me with these quotes? The single quotes are very hard to
master.

Look, to escape a quote, double it up:

Response.write "here is a literal quote: "" - see?"

Until you get the hang of it, don't try to do it all at once. Start with the
string fragments:

sHTML= "bgcolor="
response.write sHTML

Running this should result in:
bgcolor=

Now you want an opening quote, so change it to:
sHTML= "bgcolor="""
response.write sHTML

Running it should result in
bgcolor="

Now add the variable:

sHTML= "bgcolor=" & tblcolor

Test it.
Add the closing quote:

sHTML= "bgcolor=" & tblcolor & """"

Test it.
Now add the word "style=":

sHTML= "bgcolor=" & tblcolor & """ style="

Again, test it.
Add the opening quote:
sHTML= "bgcolor=" & tblcolor & """ style="""

Keep going ...

HTH,
Bob Barrows
 
S

scott

I'm getting better at double quotes, but this is confusing because I'm not
sure about js event syntax. I've tried everything and just get errors.

MY CODE:

Response.Write "bgcolor=" & tblcolor & style=""cursor:default;""
onMouseOver="this.bgColor=""'#e6e6e6'"" onMouseOut="this.bgColor='" &
tblcolor & "'"

HTML RESULTS:

bgcolor="whitesmoke" style="cursor:default;"
onMouseOver="this.bgColor='#e6e6e6'" onMouseOut="this.bgColor='whitesmoke'"
 
E

Evertjan.

scott wrote on 21 aug 2005 in microsoft.public.inetserver.asp.general:
Below in GOOD CODE, I have a mix of ASP/HTML that works. I'm trying to
convert the code into all ASP, but I'm failing in BAD CODE. Can
someone help me with these quotes? The single quotes are very hard to
master.


BAD CODE:

sHTML=sHTML & "bgcolor=" & tblcolor & style=""cursor:default;""
onMouseOver="this.bgColor=""'#e6e6e6'"" onMouseOut="this.bgColor='" &
tblcolor & "'"


sHTML=sHTML & "bgcolor=' " & tblcolor & " ' "
sHTML=sHTML & "style='cursor:default;' "
sHTML=sHTML & "onMouseOver='this.bgColor=#e6e6e6' "
sHTML=sHTML & "onMouseOut='this.bgColor=\' " & tblcolor & " \'' "


However I would define the colour in style too:


sHTML=sHTML & "style='cursor:default;background-color:" & tblcolor & ";' "
sHTML=sHTML & "onMouseOver='this.style.backgroundColor=#e6e6e6' "
sHTML=sHTML & "onMouseOut='this.style.backgroundColor=\' "
sHTML=sHTML & tblcolor & " \'' "

Not tested.

You should test this by view-sourcing the clientside"in-browser" result.
 
S

scott

thanks. what does the \ mean? i haven't seen that symbol used with this type
of syntax before.
 
B

Bob Barrows [MVP]

scott said:
thanks. what does the \ mean? i haven't seen that symbol used with
this type of syntax before.
In vbscript, you tell te compiler to ignore what a character usually means
("escaping " it) by doubling it. In jscript, you escape a character by
preceding it with a backslash.

Your confusion is arising because you are using vbscript to generate strings
that will be interpreted by the jscript engine.

Bob Barrows
 
B

Bob Barrows [MVP]

What errors? This result looks correct to me ... Oh, does HTML RESULTS
contain what you want the results to be? Your code would not return those
results ...

I would have used the style property instead of the deprecated bgColor. Try
this:

Response.Write "style=""cursor:default; background-color:" & _
tblcolor & """ onMouseOver=""this.style.backgroundColor='" & _
"#e6e6e6'"" onMouseOut=""this.style.backgroundColor='" & _
tblcolor & "'"""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top