Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Characters in database field interferring with script 1

Status
Not open for further replies.
Sep 27, 2001
179
AU
Hi

I have been working on some ASP pages for a while and all was going well until I had a problem which only after a great deal of time working on having a realised what it is. Unfortunately I don't know how to solve!

I am pulling back data from a database in a grid which then has option to 'zoom' on a record. I am using an SQL query to grab the data into a recordset.

Sometimes the field in the database can have the characters ' > < " which in some cases is interferring with the code as it sees these characters as a terminator.

I suspect this must be a common hurdle but how do I get the ASP to see the data as a whole field?

Thanks

Rob
 
if you're outputting the data right toa web page, just Server.HTMLEncode(data) it so that it's translated into a viewable form instead of trying to be part of the page.

[thumbsup2]DreX
aKa - Robert
 
Hi

Thanks for the reply I couldn't get that to work. The code which is producing the problem is as follows - I think I am combining VBSctrip and Javascript.

Code:
Response.Write ("<td bgcolor=" & sBKColour & "><font color=" & sFTColour& " face=Arial size=1><a onclick=ZoomAct('"& sRecidArray(iCount) &"')>Zoom</a></td></font>")

I have a function called ZoomAct which is launch on the Onclick event, which I am then passing the contents of an array.

However when the script is run I get some 'Unterminated string constant' errors, depending on the number of database fields that have > contained in them.

The output is then corrupted, e.g. Normally it should just say 'Zoom' but it seems to write the code so when a database field has a > character the word 'Zoom' is suffixed by the remaining contents of the array after the > character, e.g. =(_AEZoom.

The reason the array has these characters is because it is a unique ID from the database.

Thanks

Rob

 
Replacing
Code:
sRecidArray(iCount)
with
Code:
Server.HTMLEncode(sRecidArray(iCount))
didn't work, then?
 
normally the onClick behaviour in a link would be enclosed in quotes for correct syntax so possibly

Code:
<a onclick='ZoomAct('"& sRecidArray(iCount) &"')'>

Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Hi

Using

Code:
Server.HTMLEncode(sRecidArray(iCount))

stopped the output being corrupted but the errors did not for those fields in the database with a > character.

Rob
 
Hi

Thanks for pointing me in the direction of the Server.HTMLencode() function, this did have an affect and removed two errors.

But still having some problems with this but have stripped down my code to help with my diagnosis.

I have now found that spaces are also causing the problem.

Here is a sample piece of code from my asp page:

Code:
Response.Write ("<TD>" & sRecidArray(icount) & "</td>")
Response.Write ("<TD><a onclick=alert('"& sRecidArray(icount) &"'>Link</a></td>")

The first column of the table outputs correctly, the second using the Onclick event does not.

I get an 'Unterminated string constant' error for each field in the database that has a space in it, take the space away and script runs perfectly. [mad]

Because I am trying to pull a unique record ID I can't change the field I wish to use.

Any help will be appreciated!

Thanks

Rob




 
Two things:
1. You need to wrap the onClick event in quotes.
2. You have no closing parenthesis for the alert box
 
Hi

Sorry guilty of typo, My code is as follows:

Code:
Response.Write ("<td><a onclick=alert('"& sRecidArray(iCount) &"')>Zoom</a></td>")

I have tried putting the OnClick in Quotes but get errors or disables the hyperlink, could you show me where - sorry I've looked at this for so long that I can't focus :)

Rob
 
Response.Write ("<td><a href=""javascript:alert('"& sRecidArray(iCount) &"')"" onclick=""alert('"& sRecidArray(iCount) &"')"">Zoom</a></td>")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top