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

Replace function not working

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
I have this code
if (String(Request.QueryString("adType")) != "undefined"){
var adType = Request.QueryString("adType");
}
var adID = 1;
if (String(Request.QueryString("ID")) != "undefined"){
var adID = Request.QueryString("ID");

Now I need to rid adID of characters like "<", ">" and quotes "
I use adID = adID.Replace("<",""); but it throws an error that fucntion is nto supported. I also tried lower caps same results!
 
adID = adID.Replace("<","");
[tt]adID = adID.[red]r[/red]eplace([blue]/</g[/blue],""); [/tt]
 
Thanks!
Now I am still getting the error. The ADID is a numeric value and when I apply replace, i get "method not supported" exception. How can I convert ADID to string? toString() does nto work (also throws error)
 
To be more specific, ADID is
%27%22%29%3Cscri+id%3D%2280000000%22+%2F%3E
The value is a parameter passed in QS

When I try to run
adID = adID.replace(/</g,"");

on that it gives me error, method is nto supported

thanks
 
This should replace the single quotes, double quotes, and less than sign with a blank string:
Code:
adID = String(adID).replace(/\<|\'|\"/g, "");

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
The core problem is that after executing
var adID = 1;
if (String(Request.QueryString("ID")) != "undefined"){
var adID = Request.QueryString("ID");

adID is eithed a numeric or an object (but not a string).
This is why .replace is not defined.

Try:
var adID = Request.QueryString("ID")(); or
var adID = String(Request.QueryString("ID"));

These will assign a 'real' string to adID so .replace will work jut fine both with a simple string to look for and with a regular expression.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top