April 17th, 2008

You are currently browsing the articles from Java Blog - Java, J2EE, SOA, Spring and Hibernate written on April 17th, 2008.

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.