PDA

View Full Version : Data being evaluated as code!


ScottInTexas
12-19-2002, 01:49 PM
My data which comes from Excel spreadsheet is being evaluated as code. I keep getting "unterminated string constant in ..." error. Sometimes I get an error calling for ) and sometimes ;.

The data is 4 columns and two of them are strings.

This gets the string and builds the table cells

<TD width='15%'>" & cstr(objRS.Fields(LPPs)) & "</TD>"

This writes the giant string to the page

document.frames("hdrFrame").document.write("<%=hdrDiv%>");
document.frames("tblFrame").document.write("<%=dataTable%>");


How can I build the cells so that any character from the data is allowed?

Thanks a lot everyone.

raf
12-19-2002, 02:37 PM
Did you try encoding the string with

server.HTMLEncode(rsRecordsetname.Fields("variablename"))

?

ScottInTexas
12-19-2002, 03:04 PM
Thanks RAF,

I tried your suggestion but got the same error. I wrote a little routine in VB to see what was going on at the point the error claims I have a problem. Character 7208 is the y in the style in the TD tag. Well down the list from the beginning.

I was able to get debuggin going with InterDev and when I view the incoming data the text is riddled with highlighted key words.

It is in the way I am giving the vbscript variables to the javascript write function. By the way, it does not occur on all files!

Thanks,

whammy
12-20-2002, 01:40 AM
If I'm not mistaken you're sending server-side data to client-side javascript?

If so, you'll need to "comment out" single quotes, etc. when you intend to use the data client-side - so you don't get an error, i.e.:

myjavascriptstring = Replace(myjavascriptstring,"'","\'")

since javascript will error out on the client side if single quotes are not escaped, and you are using single quotes in the javascript itself. This also applies to other characters potentially, depending on what might be used in your client-side javascript.

Hope this helps... :)

glenngv
12-20-2002, 02:37 AM
read this similar thread:
http://www.codingforums.com/showthread.php?s=&threadid=10513

whammy
12-20-2002, 02:40 AM
Good find, Glenn - you never cease to amaze me. ;)

glenngv
12-20-2002, 02:57 AM
I just remembered we have solved this problem before. I remembered you named your function EscapeJS. That's the keyword I used to search that thread. :)

whammy
12-20-2002, 03:46 AM
Better memory than me... ;) I guess that says something for my function naming conventions though. :D

ScottInTexas
12-20-2002, 07:04 PM
Thanks to all of you for your help. I used glenn's EscapeBacklash function. I hope that's OK. Thanks Glenn.

I ended up deleteing the line to replace \ with \\ because I got nothing (no data, nothing). But other than that it appears to work perfectly !:D

Thank you so much.

I hear a beer calling my name! I'll buy y'all one also!