/    Sign up×
Community /Pin to ProfileBookmark

working solution to parsing values and javascript links

I now have two working features, but only one gives me true flexability in capturing variables. Here is code below. not tested on older browsers but it does work on Netscape 7 and IE 6.

If you connect to the code below from a link like:

codebelow.html?blah1=blah2&blah3=blah4

than the links values are saved and then passed on to future pages.

here it is:

<html>
<head>

<script language=”JavaScript”>
function LoadPage(thePage){
var qs = location.search.substring(1);
var nv = qs.split(‘&’);
var url = new Object();
for(i = 0; i < nv.length; i++)
{
eq = nv[i].indexOf(‘=’);
url[nv[i].substring(0,eq).toLowerCase()] = unescape(nv[i].substring(eq + 1));
}

alert(thePage + ‘?’ + unescape(qs));
location.href = thePage + ‘?’ + unescape(qs);
}

</script>

</head>

<body>

<a href=javascript:LoadPage(“page1.html”)>page 1</a>

<a href=javascript:LoadPage(“page3.html”)>page</a>

</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Jeff_MottOct 31.2003 — You should perform some testing for how your script handles checkboxes and multiple select menus.

Other things to make note of:

* [url=http://www.w3.org/TR/html401/appendix/notes.html#h-B.2.2]The W3C recommends the semi-colon be allowed in place of an ampersand.[/url]

*
[font=courier]unescape()[/font] will not transpose plus signs to spaces.

* The name portion of the name/value pairs is also URL encoded and should be decoded.
Copy linkTweet thisAlerts:
@polmstedauthorOct 31.2003 — I showed the code to a friend and he helped me simplify it.

This works well (on IE and Netscape, including Netscape 4.7)

<html>

<head>

<script>

function LoadPage(thePage){

location.href = thePage + unescape(location.search);

}

</script>

</head>

<body>

<a href=javascript:LoadPage("page3.html")>page3</a>

</body>

</html>
×

Success!

Help @polmsted spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...