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!

Change The QueryString 2

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
0
0
IN
Is it possible to change the querystring of a URL by, say, clicking a radio button or any other Form elemnt using JavaScript? For eg. an HTML Form has 2 related radio buttons - 'admin' & 'nonadmin'. Suppose a user is visiting the page Now if the user clicks the 'nonadmin' radio button, the querystring (& of course the URL!!) should change to Can this be accomplished using JavaScript?

Thanks,

Arpan
 
Hi Jeff,

Thanks for your response. It indeed turned out to be a helpful one. Another question I would like to ask you is as you must be aware of, querystrings are nothing but 'name-value pairs'. For eg. (just in case if you are not aware of the name-value pair), if the URL is


then 'status' is the name where as 'admin' is the value. Now using JavaScript is it possible to collect each & every name-value pair? For eg. if the URL is


I want JavaScript should collect each & every name-value pair so that when the nonadmin radio button is clicked, the URL can be changed to


This is because when the nonadmin radio button is clicked, I have to take the rest of the querystring other than status=admin into consideration so that except for the name 'status' in the querystring, the rest of the querystring remains as it is & does not change. If I don't take into consideration the rest of the querystring, clicking the nonadmin radio button will change the URL to


& thus the rest of the querystring (i.e. login=arpan&id=34) will be neglected which is what I don't want. Also please note that the entire querystring is generated dynamically for which I am using ASP i.e. the value of the name 'login' in the querystring can be anything other than arpan & same is the case with the name 'id' in the querysting.

Thanks once again for your help & co-operation,

Regards,

Arpan
 
Hi Arpan,
You can use given below function to get the names/value pair of the queryString.
Hope it will help.

var names = new Array();
var values = new Array();
function value_pair()
{
//var qryString = " var qryTemp = qryString.substr(qryString.indexOf("?")+1);
var name_value = qryTemp.split("&");

for (var cntr=0; cntr < name_value.length ; cntr++)
{
names[cntr] = name_value[cntr].substr(0,name_value[cntr].indexOf(&quot;=&quot;));
values[cntr]= name_value[cntr].substr(name_value[cntr].indexOf(&quot;=&quot;)+1);
}

} Experience teaches slowly and at the cost of mistakes [pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top