473,320 Members | 1,900 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,320 software developers and data experts.

Accessing web page parameters

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
6 5127
"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
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
> 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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: stjulian | last post by:
I have a stored procedure that is supposed to 1. Increment a counter in Table A via a transaction 2. Use this value as the primary key to add in an address to customers Table B (Referenced as a...
4
by: Paul Brant | last post by:
Hi all, I have a page with an IFRAME in it. From a script in the main ( parent ) page I instruct the IFRAME to load a specific URL. The URL contains parameters that are processed by the server....
8
by: Christopher Weaver | last post by:
I'm having trouble accessing the value of an output parameter of a stored procedure. The SP looks like this: SET TERM ^ ; CREATE PROCEDURE SP_NEW_TASK RETURNS ( "uidTask" INTEGER) AS begin
0
by: George | last post by:
Hello, I'm running an ASPX application "WebApplication1" which consumes a web service (service1.asmx) hosted on a machine with IP (128.1.7.x) . The web service is located in the intranet. The...
1
by: Garth Wells | last post by:
Using an example in the Jan 2006 release of the Enterprise Library, I came up with the code shown below to create a DAL method for returning several columns of a single row. I place the output...
1
by: Nestor | last post by:
Hello all, I'm begining in the web services world and I've reading about how to invoke them using javascript from Mozilla browser (version 2.0 in my case). I found a very interesting example...
1
by: Greg Scharlemann | last post by:
There is probably an easy solution to this that I've overlooked somewhere... I have a main file, call it main.php, and an include file, myInclude.php. I'm accessing main.php via:...
0
by: TechWitch | last post by:
I've seen a number of posts from frustrated folks about this topic, with not much offered as a solution. I actually managed to get this to work today, so I thought I'd post for the benefit of...
4
by: imranabdulaziz | last post by:
Dear All, I am using asp.net2.0, C#, sql2005 using Visual studio 2005 Let Me explain the scenario I have checkboxlist containg 15 field. Based on no of checked field . I created...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you▓ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.