Embedded quotes in HTML 
Author Message
 Embedded quotes in HTML

Hi all,

I'm using VBScript to generate some formatting code in an HTML page.  When I
MouseOver an area of the screen, I want to change some caption somewhere
(enclosed in a SPAN tag) in order to provide a description of what clicking
on that area will cause to happen (kinda like the text on a Windows app's
status bar).  I'm displaying a GIF (strGIF) and a string (strDesc) in a
table (for proper formatting):

 strOnMouseOver = "idDesc.innerHTML=" + chr(34) + _
  "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>" + _
   "<TR>" + _
    "<TD><IMG SRC=..\..\icons\" + strGIF + "></TD>" + _
    "<TD WIDTH=5></TD>" + _
    "<TD>" + strDesc + "</TD>" + _
   "</TR>" + _
  "</TABLE>" + chr(34)

This string, in turn, is used in a table cell:

 strCell = "" + _
  "<TD HEIGHT='23'" + _
     " WIDTH='70'" + _
     " ALIGN='RIGHT'" + _
     " VALIGN='BOTTOM'" + _
     " BGCOLOR='" + strColor + "'" + _
     " onmouseover='" + strOnMouseOver + "'" + _
     " onmouseout='" + strOnMouseOut + "'" + _
     " onclick='" + strClickEvent + "'>Click me" + _
  "</TD>"

[...]
Document.Write( strCell )
[...]
<SPAN ID='idDesc'></SPAN>

Here's the problem--I generally surround all attribute values by quotes
(either single or double, as it's generally good practice), however in this
case I had to remove them all in the strOnMouseOver string, because that
string itself eventually gets embedded within single quotes
(onmouseover='[whatever]' in strCell).  If I add them back, the parser ends
up "seeing" something like:

onmouseover='idDesc.innerHTML="<TABLE BORDER='0'.......>"'

...then of course the first quote surrounding the 0 above is paired up with
the very first quote (just before idDesc--it's intrepreted as the closing
quote).

I'm fortunate enough (for now) that this works simply by leaving out the
quotes, but that's just dumb luck.  What if the path to the IMG above
contained a space?  That'd throw everything off; whatever came after the
space would be interpreted as the next attribute.  I *need* to have the IMG
tag's SRC attribute using quotes.

How can I do this?  I've tried using &quot, chr(34) and chr(39) in various
combinations, to no avail.  Is there any way in VBScript to escape single or
double quotes so it'd work in this context?

(the code pasted above might be a bit difficult to read using a
proportional-spaced font, so you might want to paste it back in something
like Notepad using a fixed-sized font)



Sun, 06 Feb 2005 22:19:09 GMT  
 Embedded quotes in HTML
You can escape double-quote characters inside of a VBScript string simply by
doubling the double-quotes.  E.g.,

    str = "<table border=""0"">"

will result in the variable str being populated with the following string:
<table border="0">

So, something like:

    onmouseover="idDesc.innerHTML='<TABLE BORDER=""0"".......>';"

might give you what you're looking for.

Hope that helps.

- Tom Kiefer


Quote:
> Here's the problem--I generally surround all attribute values by quotes
> (either single or double, as it's generally good practice), however in
this
> case I had to remove them all in the strOnMouseOver string, because that
> string itself eventually gets embedded within single quotes
> (onmouseover='[whatever]' in strCell).  If I add them back, the parser
ends
> up "seeing" something like:

> onmouseover='idDesc.innerHTML="<TABLE BORDER='0'.......>"'

> ...then of course the first quote surrounding the 0 above is paired up
with
> the very first quote (just before idDesc--it's intrepreted as the closing
> quote).



Mon, 07 Feb 2005 00:13:45 GMT  
 Embedded quotes in HTML

Quote:
> You can escape double-quote characters inside of a VBScript string simply
by
> doubling the double-quotes.  E.g.,

>     str = "<table border=""0"">"

> will result in the variable str being populated with the following string:
> <table border="0">

> So, something like:

>     onmouseover="idDesc.innerHTML='<TABLE BORDER=""0"".......>';"

> might give you what you're looking for.

> Hope that helps.

> - Tom Kiefer


Tom,

That didn't work directly (more "unterminated string constant" messages),
but it did sent me in the right direction.  This works:

strCell = ... + " onmouseover=''" + strOnMouseOver + "''" + ...

(strOnMouseOver surrounded with two single quote characters)

...and

strOnMouseOver = "idDesc.innerHTML=" + chr(34) + ... + <TD><IMG
SRC='..\..\icons" + strGIF + "'></TD>" + ... + chr(34)

...so in the end I only have one spot where I had to add in an extra set of
quotes.  I can live with this solution.

Thanks.



Mon, 07 Feb 2005 02:10:08 GMT  
 Embedded quotes in HTML
instead of ' try quot;

Quote:
>-----Original Message-----
>You can escape double-quote characters inside of a

VBScript string simply by
Quote:
>doubling the double-quotes.  E.g.,

>    str = "<table border=""0"">"

>will result in the variable str being populated with the
following string:
><table border="0">

>So, something like:

>    onmouseover="idDesc.innerHTML='<TABLE

BORDER=""0"".......>';"
Quote:

>might give you what you're looking for.

>Hope that helps.

>- Tom Kiefer


>> Here's the problem--I generally surround all attribute
values by quotes
>> (either single or double, as it's generally good

practice), however in
Quote:
>this
>> case I had to remove them all in the strOnMouseOver

string, because that
Quote:
>> string itself eventually gets embedded within single
quotes
>> (onmouseover='[whatever]' in strCell).  If I add them
back, the parser
>ends
>> up "seeing" something like:

>> onmouseover='idDesc.innerHTML="<TABLE

BORDER='0'.......>"'
Quote:

>> ...then of course the first quote surrounding the 0
above is paired up
>with
>> the very first quote (just before idDesc--it's

intrepreted as the closing
Quote:
>> quote).

>.



Mon, 07 Feb 2005 07:30:59 GMT  
 Embedded quotes in HTML
Hi Homer,

Using a double quotes in VBScript string shoud be work. In addition, I have
found a probklem in your source: Don't append a Chr(34) to the end of the
string contained in variable strOnMouseOver.

Below is a html page, which works on my side, please try it.


<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">

<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
Sub button1_onclick
        dim strOnMouseOver ,strGIF
        dim strCell,strColor

        strGIF = "DSC00001.JPG"

        strOnMouseOver = "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>" + _
         "<TR>" + _
          "<TD><IMG SRC=""images\" + strGIF + """></TD>" + _
          "<TD WIDTH=5></TD>" + _
          "<TD>" + strDesc + "</TD>" + _
         "</TR>" + _
        "</TABLE>"

        strColor = "red"
        msgbox strOnMouseOver
        strCell = "" + _
        "<table border=1>" + _
                "<tr><TD HEIGHT='23'" + _
             " WIDTH='70'" + _
             " ALIGN='RIGHT'" + _
             " VALIGN='BOTTOM'" + _
             " BGCOLOR='" + strColor + "'" + _
             " onmouseover='" + strOnMouseOver + "'" + _
             " onmouseout='" + strOnMouseOut + "'" + _
             " onclick='" + strClickEvent + "'>Click me" + _
          "</TD><tr></table>"

          msgbox strcell
          myspan.innerHTML = strOnMouseOver

End Sub

-->
</SCRIPT>
</HEAD>
<BODY>                                  

<INPUT type="button" value="Button" id=button1 name=button1
language=vbscript onclick=" button1_onclick">
<span id=myspan name=myspan>test</span>
</BODY>
</HTML>

Gary
This posting is provided "AS IS", with no warranties, and confers no
rights. Enjoyed ASP.NET? http://www.asp.net



Mon, 07 Feb 2005 13:30:19 GMT  
 Embedded quotes in HTML

Quote:
> Hi Homer,

> Using a double quotes in VBScript string shoud be work. In addition, I
have
> found a probklem in your source: Don't append a Chr(34) to the end of the
> string contained in variable strOnMouseOver.

Hmmm, as far as I know it does require that last chr(34), to close the one
following the innerHTML assignment:

idDesc.innerHTML= chr(34) + ... + chr(34)

Quote:
> Below is a html page, which works on my side, please try it.



(just wanna point out I'm using this in plain HTML, not ASP--not that it
should make any difference in this case)

I'm definitely going to play around with this some more, as I got it to run
on one machine, but the same code failed on another (the OnMouseOver event
just doesn't seem to get triggered).  Both were running XP Pro, one with
most currently available hotfixes, the other (the one failing) without.
I'll follow up when I have a definitive answer.



Mon, 07 Feb 2005 20:39:08 GMT  
 Embedded quotes in HTML

Quote:
> instead of ' try quot;

Tried it in various combinations/permutations.  Didn't hurt, but didn't help
either.  Thanks anyway.


Mon, 07 Feb 2005 20:39:56 GMT  
 Embedded quotes in HTML
According to your statement, the first problem has been resolved, and now
you are encounting another issue that the code doesn't work as expected.

We may need more code of yours to troubleshooting the issue.

Gary

This posting is provided "AS IS", with no warranties, and confers no
rights. Enjoyed ASP.NET? http://www.asp.net



Tue, 08 Feb 2005 15:35:53 GMT  
 Embedded quotes in HTML
Yeah, I'm still sorting out some problems...Unfortunately I don't have much
time to spend on this, but when I do, I'll post some more details and any
results.


Quote:
> According to your statement, the first problem has been resolved, and now
> you are encounting another issue that the code doesn't work as expected.

> We may need more code of yours to troubleshooting the issue.

> Gary

> This posting is provided "AS IS", with no warranties, and confers no
> rights. Enjoyed ASP.NET? http://www.asp.net



Tue, 08 Feb 2005 20:57:10 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Concatenation with embedded double-quote

2. Using an embedded quote in a javascript function call parameter

3. Embedding quotes in string var ?

4. ASP vbscript - embedded quotes syntax question

5. Single Quote (Apostrophe) in Embedded Query?

6. how to embed quotes in strings

7. embedded single quotes

8. Wish List: Embedded Quotes in VB.Net

9. Embedding Double Quotes in a String -- How?

10. embedded quotes in data

11. Help embedding quotes in strings

12. Need to embed single quote in SQL string

 

 
Powered by phpBB® Forum Software