sending values through URL

I am trying to send a variable from one page to another through the URL.

I am using this line in the first page :
document.location.href="./pageOne.html?MyVariable=value";

and it works, but on the new page, I do not know how to take the value from the URL....please help me.

Comments

  • with java you can retrieve text after the first '?' mark using:
    [code]
    myVars = document.location.search
    [/code]

    HTH

    : I am trying to send a variable from one page to another through the URL.
    :
    : I am using this line in the first page :
    : document.location.href="./pageOne.html?MyVariable=value";
    :
    : and it works, but on the new page, I do not know how to take the value from the URL....please help me.
    :
    :

  • : with java you can retrieve text after the first '?' mark using:
    : [code]
    : myVars = document.location.search
    : [/code]
    :
    : HTH
    :
    : : I am trying to send a variable from one page to another through the URL.
    : :
    : : I am using this line in the first page :
    : : document.location.href="./pageOne.html?MyVariable=value";
    : :
    : : and it works, but on the new page, I do not know how to take the value from the URL....please help me.
    : :
    : :
    :
    :

    Hi there,

    Here's the code I use for this method...

    [code]



    function getValue(key) {
    var searchString = unescape(document.location.search.substring(1, document.location.search.length));
    var pairs = [];
    var kv = [];
    pairs = searchString.split("&");

    for (var i = 0; i != pairs.length; i++) {
    kv = pairs[i].split("=");

    if (kv[0] == key) {
    return kv[1];
    }
    }
    }



    [/code]

    Now it's just a matter of...

    [code]

    var key1 = getValue("key1");
    var key2 = getValue("key2");

    etc...

    [/code]

    HTH
    Bradley q:)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories