By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Accessing web page parameters

P: n/a
Hi,

I need to get the web pages URL parameters sent to the web page.

eg :-

http://www.test.org/test.html?a=1&b=2&c=3

How do I get a, b, and c from JavaScript ?

Aaron

Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Aaron Gray" <an****@beeb.net> wrote in message
news:cm*******************@news.demon.co.uk...
Hi,

I need to get the web pages URL parameters sent to the web page.

eg :-

http://www.test.org/test.html?a=1&b=2&c=3

How do I get a, b, and c from JavaScript ?

Aaron

Will this help?

<html>
<head>
<title>test.hml</title>
</head>
<body>
<script type="text/javascript">
var qstr = location.search.replace(/\?/,"&");
var pair = qstr.split("&");
for (var i=1; i<pair.length; i++) {
var item = pair[i].split("=");
document.write("<br>" + item[0] + " = " + item[1]);
}
</script>
</body>
</html>
Jul 23 '05 #2

P: n/a
Hello

Try this:
<script>
var str="http://www.test.org/test.html?a=1&b=2&c=3"
var str1=str.substr(str.indexOf('?')+1) // get the string part that goes
//after the
question mark 'a=1&b=2&c=3'
var arr= new Array()
arr=str1.split(/&/) // str1 is split by
'&' into array arr=('a=1', 'b=2', 'c=3')
var arr1= new Array()
for(var i=0; i<arr.length; i++){
var arr2= new Array()
arr2=arr[i].split(/=/) // same as above, e.g.
arr3=('a', '1') or ('b', '2') or ('c', '3')
arr1.push(arr2[0]) // arr1=('a', 'b', 'c')
}
document.write(arr1[0]+' '+arr1[1]+' '+arr1[2])
</script>

Andrey
"Aaron Gray" <an****@beeb.net> сообщил/сообщила в новостях следующее:
news:cm*******************@news.demon.co.uk...
Hi,

I need to get the web pages URL parameters sent to the web page.

eg :-

http://www.test.org/test.html?a=1&b=2&c=3

How do I get a, b, and c from JavaScript ?

Aaron

Jul 23 '05 #3

P: n/a
> Will this help?

<html>
<head>
<title>test.hml</title>
</head>
<body>
<script type="text/javascript">
var qstr = location.search.replace(/\?/,"&");
var pair = qstr.split("&");
for (var i=1; i<pair.length; i++) {
var item = pair[i].split("=");
document.write("<br>" + item[0] + " = " + item[1]);
}
</script>
</body>
</html>


Cheers, if there is no better solution then yes :)

Thank you,

Aaron
Jul 23 '05 #4

P: n/a
On Wed, 10 Nov 2004 20:03:24 -0000, Aaron Gray wrote:
Cheers, if there is no better ..
*
..solution then yes :)


* Define 'better'?

There are certainly more complicated scripts that will account
for multiple values of a single parameter, or offer a function
to allow other scripts to make a request for specific parameters
they are expecting.

These are longer than the script McKirahan supplied, but if you
need the extra functionality, they are 'better'.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Jul 23 '05 #5

P: n/a

"Andrew Thompson" <Se********@www.invalid> wrote in message
news:dx****************************@40tude.net...
On Wed, 10 Nov 2004 20:03:24 -0000, Aaron Gray wrote:
Cheers, if there is no better ..


*
..solution then yes :)


* Define 'better'?


An already exist named index array of parameters :)

Aaron
Jul 23 '05 #6

P: n/a
In article <cm*******************@news.demon.co.uk>, an****@beeb.net
says...
Will this help?

<html>
<head>
<title>test.hml</title>
</head>
<body>
<script type="text/javascript">
var qstr = location.search.replace(/\?/,"&");
var pair = qstr.split("&");
for (var i=1; i<pair.length; i++) {
var item = pair[i].split("=");
document.write("<br>" + item[0] + " = " + item[1]);
}
</script>
</body>
</html>


Cheers, if there is no better solution then yes :)


You decide if it's better:
http://kibo.org.uk/programming.php?grp=JavaScript&id=5

--
Hywel
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.