View Full Version : QueryStrings in HTML....
saurup
01-12-2001, 08:13 AM
can I write "xyz.htm?uname=abc" and then accept the querystring "uname" in javascript (client side) as in ASP ???
kdjoergensen
01-12-2001, 11:29 AM
To retrieve everything after the '?':
var sea = window.location.search.substring(0);
example: mydomain.com/page2.html?red;blue;
var sea = window.location.search.substring(0);
// sea = "red;blue;";
var seaAry = sea.split(';');
// seaAry[0] = "red";
// seaAry[1] = "blue";
document.all.myDiv.style.color = seaAry[0];
document.all.myDiv.style.backgroundColor = seaAry[1];
you can obviously also pass javascript data and use eval() to create it into javascript references:
example by passing variables to another page:
domain.com/page2.html?mymoney=200;mytime=24;
sea = window.location.search.substring(0);
seaAry = sea.split(';');
for (var i=0;i<=seaAry.length;i++) {
eval(seaAry[i]);
}
Note: if you use spaces or non-letters/ numbers you should escape your data before sending. similar you should unescape before manipulating data.
saurup
01-14-2001, 01:39 AM
Thank you sir, it worked out perfectly !!
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.