Results 1 to 3 of 3

Thread: Passing forward variables

  1. #1
    Join Date
    Mar 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Passing forward variables

    Hi,

    I found a nice script by jscheuer1 in the html forum that is an example of passing variables (or or better said their values) from one window to another by javascript.

    Now what if I want to use these values and then pass it forward to one more window? I tried it in the following way but it does not work.

    What I tried to do was to return the value of the variable with a function (givethevalue) and so using it outside the actual javascript routine. I know that what I need is the proper syntax for the last code line but can not find out. Could you please help?

    File 1:
    <html>
    <head>
    <title>javascript variable passing - page 1</title>
    </head>
    <a href="ss.htm?var1=33">Send Variable</a>
    </body>
    </html>


    File 2, named ss.htm:
    <html>
    <head>
    <title>javascript variable passing - page 2</title>
    </head>
    <body>
    <form name="recieve">
    <input type="hidden" name="var1">
    </form>
    <script language="javascript">
    var locate = window.location;
    document.recieve.var1.value = locate;
    var text = document.recieve.var1.value;
    function delineate(str) {
    theleft = str.indexOf("=") + 1;
    theright = str.indexOf("&");
    return(str.substring(theleft, str.length));
    }

    function givethevalue() {
    text2 = "";
    text2 = "tt.htm?" + delineate(text);
    return(text2);
    }
    </script>

    <p>The passed variable can now be passed to a new file:</p>
    <p><a href="javascript:givethevalue()">New window</a></p>

    </body>
    </html>

    Also I tried this. Does not work either:

    function givethevalue() {
    text2 = "";
    text2 = delineate(text);
    return(text2);
    }
    </script>

    <p>The passed variable can now be passed to a new file:</p>
    <p><a href="tt.htm?+javascript:givethevalue()">New window</a></p>

    </body>
    </html>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Instead of going through all that, from my original example for page 2:

    Code:
    <html>
    <head>
    <title>javascript variable passing - page 2</title>
    </head>
    <body>
    <form name="recieve">
    <input type="hidden" name="var1">
    </form>
    <script language="javascript">
    var locate = window.location;
    document.recieve.var1.value = locate;
    var text = document.recieve.var1.value;
    function delineate(str) {
    theleft = str.indexOf("=") + 1;
    theright = str.indexOf("&");
    return(str.substring(theleft, str.length));
    }
    document.write('<a href="nextpage.htm?var1=' +delineate(text)+ '">New Window</a>');
    </script>
    </body>
    </html>

  3. #3
    Join Date
    Mar 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Now I understand:

    Use document.write and let this work inside the javascript. I built this into my routine and it works like a charm.

    Thank you again!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •