tags:

views:

1308

answers:

3

I have two Pages of JQuery...Page1 & Page2 and I'm able to get Input In Page1

The somval=1000$

The page 1 user enters the somevalue.I have stored in Value var val=somval;

Now In second Page I need to Get the Result of somvalue in page 1. of course two pages using My1.js My2.js respectively

How to share the values from one jQuery file to other js or how to Get the value from page1 value, to page2

Any idea how to tackle this?

+3  A: 

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.

Gerald Kaszuba
A: 

The problem isn't specific to jQuery (ie. it probably haven't a specific solution, unless I am mistaken), but to any Web page.
Gerald gave the URL query string solution, the other classical solution, if you want to be independent of a server, is to use cookies, they are made for that!
Using a server, you have session data, hidden fields, Ajax save and restore, etc.

PhiLho
A: 

You could set the data in a cookie, http://www.quirksmode.org/js/cookies.html has functions for reading and writing cookies.

stuartloxton