passing variable - no answer?!

Discussion in 'Javascript' started by Geoff Cox, Sep 29, 2005.

  1. Geoff Cox

    Geoff Cox Guest

    Hello,

    I have written before that I can pass a variable from page 1 to page 2
    if I call the variable "name".

    Stephen Chalmers has written,

    >'name' is effectively a reserved word as the variable window.name is
    >created automatically, but is not read-only.
    >Use more imaginative names for variables.


    Does this explain why I can pass the variable from one page to
    another?

    It does seem to be much simpler that other methods, eg passing the
    value with the URL etc.

    Does doing this have any negative side effect?


    Cheers

    Geoff
     
    Geoff Cox, Sep 29, 2005
    #1
    1. Advertisements

  2. Geoff Cox

    ASM Guest

    Geoff Cox a écrit :

    > Does this explain why I can pass the variable from one page to
    > another?


    nothing best than a try-demo :

    file 'page1.htm' :

    <html> <title>page 1</title>
    <h3>page 1</h3>
    <form action="page2.htm" onsubmit="window.name=this.Name.value">
    Enter your name : <input type=text name="Name">
    <input type=submit value=GO>
    </form></html>

    file 'page2.htm' :

    <html> <title>page 2</title>
    <body onload="document.forms[0][0].value = window.name;">
    <h3>page 2</h3>
    <form>
    Your name is : <input type=text name="Name">
    </form></body></html>

    > It does seem to be much simpler that other methods, eg passing the
    > value with the URL etc.


    yes, if you have only one alone value to pass

    > Does doing this have any negative side effect?


    what negative effect ?


    --
    Stephane Moriaux et son [moins] vieux Mac
     
    ASM, Sep 29, 2005
    #2
    1. Advertisements

  3. Geoff Cox

    Geoff Cox Guest

    On Thu, 29 Sep 2005 11:36:41 +0200, ASM
    <> wrote:

    >Geoff Cox a écrit :
    >
    >> Does this explain why I can pass the variable from one page to
    >> another?

    >
    >nothing best than a try-demo :
    >
    >file 'page1.htm' :
    >
    ><html> <title>page 1</title>
    ><h3>page 1</h3>
    ><form action="page2.htm" onsubmit="window.name=this.Name.value">
    >Enter your name : <input type=text name="Name">
    ><input type=submit value=GO>
    ></form></html>
    >
    >file 'page2.htm' :
    >
    ><html> <title>page 2</title>
    ><body onload="document.forms[0][0].value = window.name;">
    ><h3>page 2</h3>
    ><form>
    >Your name is : <input type=text name="Name">
    ></form></body></html>
    >
    >> It does seem to be much simpler that other methods, eg passing the
    >> value with the URL etc.

    >
    >yes, if you have only one alone value to pass
    >
    >> Does doing this have any negative side effect?

    >
    >what negative effect ?


    Stephane.

    Thanks for trying this approach. I haven't seen any mention of this
    befofe.

    I was wondering whether if this uses "a sort of reserved word" whether
    this can cause any problems?

    Cheers

    Geoff
     
    Geoff Cox, Sep 29, 2005
    #3
  4. Geoff Cox

    ASM Guest

    Geoff Cox a écrit :
    > On Thu, 29 Sep 2005 11:36:41 +0200, ASM
    > <> wrote:
    >
    > Stephane.
    >
    > Thanks for trying this approach. I haven't seen any mention of this
    > befofe.
    >
    > I was wondering whether if this uses "a sort of reserved word" whether
    > this can cause any problems?


    as said by otherwise

    'name' is a reserved word for everything in javascript

    in this try-demo this reserved word is used for what it was done
    that's to say : to give a name to an object

    because 'window' is the all first object in javascript
    and
    because 'window' can be omitted

    if your window has a name and you do i.e. alert(name)
    that would have to open an alert-box with the name of the window

    so, this try-demo can become :

    file 'page1.htm' :

    <html> <title>page 1</title>
    <script type="text/javascript">
    function go(aName) { name=aName; }
    </script>
    <h3>page 1</h3>
    <form action="page2.htm">
    Enter your name :
    <input type=text name="Name" onchange="go(this.value);">
    <input type=submit value=GO>
    </form></html>

    file 'page2.htm' :

    <html>
    <title>page 2</title>
    <body onload="document.forms[0].Name.value = name;">
    <h3>page 2</h3>
    <form>
    Your name is :
    <input type=text name="Name">
    </body></form></html>


    As you can see now, using IE (don't more work with FF),
    what was your variable 'name'
    was in fact the reserved word 'name'
    and, because used alone, was : name of window



    This particularism (a window records its name)
    is useful with popups



    --
    Stephane Moriaux et son [moins] vieux Mac
     
    ASM, Sep 29, 2005
    #4
  5. On 29/09/2005 09:46, Geoff Cox wrote:

    > [Using global 'name'] Does this explain why I can pass the variable
    > from one page to another?


    The property that you are using is a property of the tab or browser
    instance, rather than the document, unlike most properties of the global
    object.

    > It does seem to be much simpler that other methods, eg passing the
    > value with the URL etc.


    Parsing values out of the query string (or a cookie) is hardly a
    difficult task.

    > Does doing this have any negative side effect?


    Other than the fact that it might not work? There's no particular reason
    why it should, and indeed it doesn't in Firefox.

    Mike

    --
    Michael Winter
    Prefix subject with [News] before replying by e-mail.
     
    Michael Winter, Sep 29, 2005
    #5
  6. Geoff Cox

    Geoff Cox Guest

    On Thu, 29 Sep 2005 16:15:55 GMT, Michael Winter
    <> wrote:

    >> Does doing this have any negative side effect?

    >
    >Other than the fact that it might not work? There's no particular reason
    >why it should, and indeed it doesn't in Firefox.


    Michael,

    OK - that is a negative effect.

    Thanks

    Geoff







    >
    >Mike
     
    Geoff Cox, Sep 29, 2005
    #6
  7. Geoff Cox

    Geoff Cox Guest

    On Thu, 29 Sep 2005 17:22:52 +0200, ASM
    <> wrote:

    >so, this try-demo can become :
    >
    >file 'page1.htm' :
    >
    ><html> <title>page 1</title>
    ><script type="text/javascript">
    >function go(aName) { name=aName; }
    ></script>
    ><h3>page 1</h3>
    ><form action="page2.htm">
    >Enter your name :
    ><input type=text name="Name" onchange="go(this.value);">
    ><input type=submit value=GO>
    ></form></html>
    >
    >file 'page2.htm' :
    >
    ><html>
    ><title>page 2</title>
    ><body onload="document.forms[0].Name.value = name;">
    ><h3>page 2</h3>
    ><form>
    >Your name is :
    ><input type=text name="Name">
    ></body></form></html>
    >
    >
    >As you can see now, using IE (don't more work with FF),
    >what was your variable 'name'
    >was in fact the reserved word 'name'
    >and, because used alone, was : name of window
    >
    >
    >
    >This particularism (a window records its name)
    >is useful with popups



    Thanks Stephane.

    Food for thought!

    Cheers

    Geoff
     
    Geoff Cox, Sep 29, 2005
    #7
  8. Geoff Cox

    Geoff Cox Guest

    On Fri, 30 Sep 2005 14:18:30 GMT, "Zoe Brown"
    <> wrote:

    >> It does seem to be much simpler that other methods, eg passing the
    >> value with the URL etc.

    >
    >no it doesn't, just pass the parameter in the query string as they were
    >intended !!


    Zoe,

    Not sure what you mean? Could you please explain?

    It is the case, as was pointed out to me, that this method does not
    work with Firefox so have moved to the form/URL approach.

    Cheers

    Geoff
     
    Geoff Cox, Sep 30, 2005
    #8
  9. Geoff Cox

    Geoff Cox Guest

    On Fri, 30 Sep 2005 18:58:23 GMT, "Zoe Brown"
    <> wrote:

    >
    >"Geoff Cox" <> wrote in message
    >news:...
    >> On Fri, 30 Sep 2005 14:18:30 GMT, "Zoe Brown"
    >> <> wrote:
    >>
    >>>> It does seem to be much simpler that other methods, eg passing the
    >>>> value with the URL etc.
    >>>
    >>>no it doesn't, just pass the parameter in the query string as they were
    >>>intended !!

    >>
    >> Zoe,
    >>
    >> Not sure what you mean? Could you please explain?
    >>
    >> It is the case, as was pointed out to me, that this method does not
    >> work with Firefox so have moved to the form/URL approach.

    >
    >which is what I said. Just use the form and use a post or get to get the
    >data.


    Zoe,

    OK - with you!

    Cheers

    Geoff





    >
    >>
    >> Cheers
    >>
    >> Geoff
    >>

    >
     
    Geoff Cox, Oct 1, 2005
    #9
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shil
    Replies:
    2
    Views:
    2,178
    Eliyahu Goldin
    Jan 2, 2007
  2. pereges
    Replies:
    7
    Views:
    555
    pereges
    Jun 1, 2008
  3. Jonas Daunoravicius
    Replies:
    5
    Views:
    411
    Peter
    Jul 17, 2003
  4. Steve Cosh
    Replies:
    1
    Views:
    216
    joewiii
    Nov 18, 2005
  5. Jonas Daunoravicius
    Replies:
    5
    Views:
    382
    Peter
    Jul 17, 2003
Loading...

Share This Page