0

I want to pass the value entered by a user in a form field from a page called "productDetail" to the form field in a page called "gmap-3".

Now normally, if both fields were on the same page, I'd just do something like :

$('#productDetail').live("pagecreate", function() {
    $('#submitPost').tap(function() {
        if ($('#postalFrom').val()== "" || null) {
            var postalCode = $('#postalFrom').val();
            alert("Enter postal code first.");
        } else {
            $('#from').val(postalCode);
        }
    });
});

But considering the form field "('#from')" is on the page "g-map3" and not "productDetails", how can I accomplish that ?

Thanks in advance !

1
  • Ok. I'll try and make it clearer if you can tell me what you don't understand in the question.
    – JFFF
    Jul 22, 2011 at 15:36

2 Answers 2

2

when going from one page to another, pass the values with the url e.g.

http://example.com?postalCode=11204&fname=john&lname=doe

then parse the url with location.search. something like

var params = location.search.substring(1,location.search.length).split("&");
for (var i = 0; i < params.length; i++)
{
  var field = params[i].split("=")[0];
  var value = params[i].split("=")[1];
  // process
}

EDIT

forgot to get rid of the "?" :P hence the substring(1,location.search.length)

2
  • prams should be params, other wise it wouldn't work. Nice answer btw!
    – Milaan
    Jul 22, 2011 at 15:40
  • Small mistake because of the fast answer, can happen? Haha, youre welcome!
    – Milaan
    Jul 22, 2011 at 15:43
1

Submit your first form as a GET so the variable appears in the query string. Then on your second form you can simply parse the query string to fetch your value.

document.location.search will contain your 'foo=1&bar=2' string

From there you'd use split() to covert that into an array: var q = document.location.search.split('=');

Now you have your array of query string parameters and grabbing the data you need to populate your form on page 2 is simple.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.