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

location query - passing a variable

Status
Not open for further replies.

jacq

Technical User
Jan 3, 2001
38
0
0
GB
i am trying to add an ID to a web page URL.
i have (in ASP) reqID = request.QueryString("ID"), and can read this with response.write, but when i try to put this value into my URL is returns nothing:
location = "../folder1/comment.asp?ID=" + reqID;

if i put location = "../folder1/comment.asp?ID=2" it works fine. is it because the variable wasn't created in javascript, and if so, how can i get the ID from the URL in javascript, ie is there a similar function to request.querystring in javascript?
 
In JavaScript, in order to get the Query, the code is
Code:
location.search
What it does is return the question mark, followed by whatever else is behind it. For example, if you tried to access
Code:
myPage.html?q=myQuery&msg=hey
, using the
Code:
location.search
property would return
Code:
?q=myQuery&msg=hey

However, I don't think you would need to do so. If you correctly defined
Code:
reqID
, it should work properly with your ASP script.
bluebrain.gif
blueuniment.gif
 
Hmm... There's a difference between the code you just posted and the code you had posted earlier. But I can tell you, in the code you just posted:

In JavaScript, in order to add a variable's value to a string, you must add it to the end of a string:
Code:
location = "../folder1/comment.asp"+reqID;
Keep in mind, too, that for the above code to work correctly, the variable
Code:
reqID
must be a String with the contents:
Code:
?ID=2

If
Code:
reqID
is just a number, you should use this code:
Code:
location = "../folder1/comment.asp?ID="+reqID;
bluebrain.gif
blueuniment.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top