Posted by: prajapatinilesh | May 11, 2009

Javascript function to get particular querystring value from URL.

Hi,

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

How to use:

here url is your js variable in which your whole url is defined.

if(url.indexOf(‘prefixVal’) != -1) {

prefixVal = getQueryStrVal(url, ‘prefixVal’);

alert(prefixVal);

}

Thanks,

Nilesh prajapati.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: