How to pass values from one page to another in jQuery

You can redirect the user to the next page with the data in a query string, then in the second page you can parse the URL.

To redirect the user you can do this:

window.location = 'page2.html?somval=" + somval;

Then in the second page you can use a function to parse the URL query string:

var qsParm = new Array();
function qs() {
    var query = window.location.search.substring(1);
    var parms = query.split("&');
    for (var i=0; i < parms.length; i++) {
        var pos = parms[i].indexOf('=');
        if (pos > 0) {
            var key = parms[i].substring(0, pos);
            var val = parms[i].substring(pos + 1);
            qsParm[key] = val;
        }
    }
}

This code was borrowed from here, although there are many ways to do it.

You mentioned jQuery, but correct me if I’m wrong, I don’t think it can do this.

Leave a Comment