473,385 Members | 1,292 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Parse querystring using javascript?


If my url is, say,
http://mysite/mypage.asp?fruit=apple...ges&sweet=cake, then how do I
get the value of "fruit", "veg" and "sweet" params using clientside
javascript?

In ASP I can use Request.Querystring("fruit") etc, but I need to get it
using clientside javascript this time.

Help?

Thanks,
Owen
Sep 7 '05 #1
2 4140
Owen wrote:

If my url is, say,
http://mysite/mypage.asp?fruit=apple...ges&sweet=cake, then how do
I get the value of "fruit", "veg" and "sweet" params using clientside
javascript?

In ASP I can use Request.Querystring("fruit") etc, but I need to get it
using clientside javascript this time.

Help?
Hi,

document.location return the current url.

Get the part after ?
split it on &

all pieces you have left are of the form:
name=value

Good luck.

Regards,
Erwin Moller

Thanks,
Owen


Sep 7 '05 #2
Owen wrote:
If my url is, say,
http://mysite/mypage.asp?fruit=apple...ges&sweet=cake, then how do I
get the value of "fruit", "veg" and "sweet" params using clientside
javascript?


if(location.search){
vals=
unescape((location.search.substring(1).replace(/\+/g," "))).split("&");
for(i=0;i<vals.length;i++){
vals[i]=vals[i].split("=");
window[vals[i][0]]=vals[i][1];
}

In your case, the script creates three global variables:
fruit="apples"
veg="cabbages"
sweet="cake"

Mick
Sep 7 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Arpan | last post by:
A link has the following URL: <a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%= Request.QueryString("cadd1") %>&cadd2=<%= Request.QueryString("cadd2") %>&cplace=<%=...
3
by: Dennis M. Marks | last post by:
I am looking for a javascript function that will parse a query string. Parameters are passed in the url: url?a=3&c=5&etc An array is returned that uses the variable name as the index. array=3...
1
by: lion | last post by:
my Problem: a query string passed into a html page doesn't display correctly on a mac I am just using html and javascript (no ASP, PHP or server side scripting) This is the query string:...
2
by: Amadelle | last post by:
Hi all, I have multiple frames which I would like to get the query string from within one of the subframes. But when I do HttpContext.Current.Request.QueryString or Request.QueryString ...
12
by: Manso | last post by:
Hi, Our sites need to support utf-8 so web.config has both request and response encoding set to utf-8. The problem is that Request.Querystring doesn't support this and we've tried to find a...
10
by: Martin Eyles | last post by:
Hi, I am getting a string passed back from a web form in the format name1:variable1;name2:variable2... I would like to split this up into several variable, such that the variable names are...
9
by: VancouverMike | last post by:
Hi there, I run into a very strange problem. I got the following url and am passing information via query string. The problem when the "sin" key in query string is blank, shown as in the...
7
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
1
by: ozzii | last post by:
Hi, Does anybody know how to parse the name value pairs in a querystring contained in a variable with asp? for those of you who might be confused, what i am trying to do is basically I have a...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.