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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apostrophe in querystring causing error, how to solve?

Status
Not open for further replies.
Try the escape() function.

Code:
VarSearchCriteria = escape(VarSearchCriteria);
window.open(...);

*cLFlaVA
----------------------------
Breaking the habit...
 
Hi, thanks for the reply.

Tried this but unfortunately I still recieve the same error...
 
There must be some sort of error message you're receiving...

*cLFlaVA
----------------------------
Breaking the habit...
 

Yes but its quite non descript:

Expected ';'

Not much help..
 
Worked fine for me with escape(). What's in your QryStringSearchParam? Also, is there any other JavaScript in your file? What line is this error pointing to?

*cLFlaVA
----------------------------
Breaking the habit...
 

Sorry I really should have provided this info at the start (was just rushing in).

The code above this querystring is:

searchparam = replace(SearchParam,"'","''")
searchparam = "'" & searchparam & "'"

and the value of searchparam is "Kelly's"

Thanks...
 
[ol]
[li]& is not a valid string concatenator. Use +.[/li]
[li]replace must be called from an object. Like this: searchparam.replace("'","''");[/li]
[li]Are you sure this is JavaScript you're showing me?[/li]
[li]Where is searchparam used in the window.open call?[/li]
[li]Keep variable names capitalized the same way. SearchParam should be searchparam.[/li]
[/ol]

*cLFlaVA
----------------------------
Breaking the habit...
 
I've really mucked this thread up, sorry. Let me show you the code from where I believe it becomes significant and where it stops being significant:


<%

CMID = request.querystring("varCMID")
AccountNo = request.querystring("varAccNo")
DamageDeclared = request.querystring("DamageDeclared")
varDmgID = request.querystring("varDmgID")
SendingPage = request.querystring("SendingPage")
DamageRetain = request.querystring("DamageRetain")


dim SearchedFor
SearchedFor = "False"

Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; Dbq= " & server.mappath("CustomerCareDamagesDb.mdb")


'DamageRetain
'*******Search code & Damage Complete and Retain Code:

if DamageRetain <> "" then

SearchCriteria = "DamagesID"
SearchParam = request("varDmgID")

else

SearchCriteria = request("Search_Criteria")
SearchParam = request("Search_Box")

end if

if SearchCriteria <> "Please Select" and SearchParam <> "" then

SearchedFor = "True"

if SearchCriteria = "Surname" then
searchparam = replace(SearchParam,"'","''")
searchparam = "'" & searchparam & "'"

end if

SQL_Search = "SELECT * FROM tblDamages WHERE (" & SearchCriteria & " = " & searchparam & ")"
Set RSSearch = MyConn.Execute(SQL_Search)



Dim strCount
strCount = 0
While NOT RSSearch.EOF AND NOT RSSearch.BOF
strCount = strCount + 1
RSSearch.MoveNext()
Wend

if strCount > 1 then


%>

<script language = "javascript">

VarSearchCriteria = '<%=SearchCriteria%>'
VarSearchParam = <%=SearchParam%>


window.open (" 'width=800, height=200, scrollbars=yes');


</script>


Thanks and sorry for wasting your time.
 


[tt]VarSearchParam = [red]"[/red]<%=SearchParam%>[red]"[/red][/tt]



?

*cLFlaVA
----------------------------
Breaking the habit...
 
UNBELIEVABLE! That's all it was, I really should have been more helpful at the start!

How does this work? because when I delimit VarSearchParam with ' instead of " it gives the same error.


MANY thanks!
 


Replace each ' and " with \' and \" in your ASP before you send it to JavaScript. Why not get rid of the garbage earlier on so you don't have to keep throwing it out?

*cLFlaVA
----------------------------
Breaking the habit...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top