473,385 Members | 1,655 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.

name/value pair in the current url

>From http://developer.irt.org/script/992.htm

=============================================

Q992 How can I accept a name/value pair in the current url and access
it as a variable and value?

If the URL is something like:

http://www.irt.org/index.htm?number=5

Then the following will create a JavaScript variable called number,
with the value of 5:

<script language="JavaScript"><!--
if (location.search.length > 0)
eval('var ' + location.search.substring(1));
//--></script>

=============================================

How can I expand this to cope with say
http://www.irt.org/index.htm?number=5&name=john&age=41
putting john into a variable called name and 41 into a variable called
age ?

Also, how can I unescape the URL if it's got spaces ?

thanks a lot

Jim

Jul 23 '05 #1
1 1550
<ja********@go.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
From http://developer.irt.org/script/992.htm


=============================================

Q992 How can I accept a name/value pair in the current url and access
it as a variable and value?

If the URL is something like:

http://www.irt.org/index.htm?number=5

Then the following will create a JavaScript variable called number,
with the value of 5:

<script language="JavaScript"><!--
if (location.search.length > 0)
eval('var ' + location.search.substring(1));
//--></script>

=============================================

How can I expand this to cope with say
http://www.irt.org/index.htm?number=5&name=john&age=41
putting john into a variable called name and 41 into a variable called
age ?

Also, how can I unescape the URL if it's got spaces ?

thanks a lot

Jim


Check this thread that started yesterday in comp.lang.javascript:
"Referencing name/values in URL string"
Jul 23 '05 #2

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

Similar topics

3
by: He Shiming | last post by:
Hi Folks, Happy holidays! I have a question regarding STL multimap. Basically, the current multimap<int,int> look like this: key=>value 1=>10, 1=>20, 1=>30,
11
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html>...
5
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the...
16
by: Bush is a Fascist | last post by:
Hi all, What do most languages call a name-value pairing? Or perhaps my question should be, why not just call it a name-value pairing? Too many syllables? Did Knuth invent a handy term for...
3
by: Jon | last post by:
Hi, I have hyperlink objects in a datagrid that redirect the user back to the current page with this syntax: <a href="mypage.aspx?id=foo"> When the page reloads, code in Page_Load then takes...
7
by: RSH | last post by:
I need to use a form element to display a list of users. I would like to store their ID "behind the scenes" so when the user selects a name the Event passes their ID. I can't find anything...
2
by: Kevin Blount | last post by:
I have an issue with trying to add a new name-pair to an existing cookie. Here's what I want to do: page1 - adds "loggedin=true" to cookie "Communities" adds "member_id=100" to cookie...
15
by: Dave Young | last post by:
I'm trying to replicate the behaviour of the Commerce.Dictionary object that was found in Commerce Server 3.0 By using a hashtable or creating a custom class that implements IDictionary, you...
2
by: Andrus | last post by:
I'm trying to compile myGeneration PropertyCollectionAll.cs file with VCS Express 2005 bot got error Error 1 The type or namespace name 'Collection' could not be found (are you missing a using...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.