URL Request Parameters using Javascript

function getRequestParameter( name ) {
name = name.replace(/[\[]/,”\\\[”).replace(/[\]]/,”\\\]”);
var regexS = “[\\?&]”+name+”=([^&#]*)”;
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return “”;
else
return results[1];
}

Let’s say you have the following URL:
http://www.foo.com/index.html?customerCode=123&consignment=321&debug=true

You want to get the value of consignment parameter so you call the javascript function as follows:
var value = getRequestParameter( ‘consignment’ );

Written by Ravi Nallakukkala on April 17th, 2008 with no comments.
Read more articles on Uncategorized.

Related articles

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> .