How to pass a parameter to a javascript through a url and display it on a page?

For instance, I have a url like this :

How do I pass a value " Use_Id = abc " to it and use javascript to display on that page ?



Shouldn't be too difficult to write your own without the need for an external library.


var GET = {};
var query ="&");
for (var i = 0, max = query.length; i < max; i++)
    if (query[i] === "") // check for trailing & with no param

    var param = query[i].split("=");
    GET[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || "");

Usage: GET.Use_id or GET["Use_id"]. You can also check if a parameter is present even if it has a null value using "Use_id" in GET (will return true or false).


Call the page

Then in that page use a javascript function like:

var urlParam = function(name, w){
    w = w || window;
    var rx = new RegExp('[\&|\?]'+name+'=([^\&\#]+)'),
        val =;
    return !val ? '':val[1];

To use it:

var useId = urlParam('Use_Id');

The second parameter w is optional, but useful if you want to read parameters on iframes or parent windows.


var qs = new QueryString()

// use_id is now available in the use_id variable
var use_id = qs.get("use_id");

Get the QueryString() code here


var querystring = window.location.querystring;
var myValue = querystring["Use_Id"];

UPDATE: Link to library (thanks @Andy E),


There's a similar question on this here What is the easiest way to read/manipulate query string params using javascript?

Which seems to recommend using jQuery's Querystring plugin:


Your server side script could read the value and set it in a hidden form field which your JS could then read.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.