passing variables?

Discussion in 'Javascript' started by George Hester, Dec 5, 2003.

  1. I have a statement such as this:

    <body onmousedown="JavaScript:var x = :xlocCur();">

    This xlocCur returns a number, integer.

    then in the body I have:

    <script type="text/javascript">
    alert(x)
    </script>

    x is undefined. How can I pass values between JavaScript islands?

    --
    George Hester
    __________________________________
     
    George Hester, Dec 5, 2003
    #1
    1. Advertising

  2. George Hester wrote on 05 Dec 2003:

    > I have a statement such as this:
    >
    > <body onmousedown="JavaScript:var x = :xlocCur();">


    "JavaScript:" above is supposed to be used as a URI specifier, not to
    determine the language of intrinsic events. To do this, declare the
    default scripting language with the following META element placed in
    the document head:

    <META http-equiv="Content-Script-Type" content="text/javascript">

    The above intrinsic event can (and /should/) be written as:

    <BODY onmousedown="var x = xlocCur()">

    > This xlocCur returns a number, integer.
    >
    > then in the body I have:
    >
    > <script type="text/javascript">
    > alert(x)


    You should qualify that call properly (window.alert).

    > </script>
    >
    > x is undefined. How can I pass values between JavaScript islands?


    Three options:

    1) Don't define the variable with the var keyword. That should place
    it in global, rather than local, scope.

    2) Define the variable (with or without var) in a script block
    outside of a function (so it becomes global). Then simply assign to
    it as normal.

    3) Use a function for the intrinsic event.

    function myEventHandler() {
    window.alert( xlocCur() );
    }

    Mike

    --
    Michael Winter
    d (replace ".invalid" with ".uk")
     
    Michael Winter, Dec 5, 2003
    #2
    1. Advertising

  3. Hmm thanks Michael. I found a way around it:

    <a onmousedown="JavaScript:var x = :xlocCur(); function(x);">

    But I like yours better.

    --
    George Hester
    __________________________________
    "Michael Winter" <> wrote in message news:Xns94486ED303292MWinterBlueyonder@193.38.113.46...
    > George Hester wrote on 05 Dec 2003:
    >
    > > I have a statement such as this:
    > >
    > > <body onmousedown="JavaScript:var x = :xlocCur();">

    >
    > "JavaScript:" above is supposed to be used as a URI specifier, not to
    > determine the language of intrinsic events. To do this, declare the
    > default scripting language with the following META element placed in
    > the document head:
    >
    > <META http-equiv="Content-Script-Type" content="text/javascript">
    >
    > The above intrinsic event can (and /should/) be written as:
    >
    > <BODY onmousedown="var x = xlocCur()">
    >
    > > This xlocCur returns a number, integer.
    > >
    > > then in the body I have:
    > >
    > > <script type="text/javascript">
    > > alert(x)

    >
    > You should qualify that call properly (window.alert).
    >
    > > </script>
    > >
    > > x is undefined. How can I pass values between JavaScript islands?

    >
    > Three options:
    >
    > 1) Don't define the variable with the var keyword. That should place
    > it in global, rather than local, scope.
    >
    > 2) Define the variable (with or without var) in a script block
    > outside of a function (so it becomes global). Then simply assign to
    > it as normal.
    >
    > 3) Use a function for the intrinsic event.
    >
    > function myEventHandler() {
    > window.alert( xlocCur() );
    > }
    >
    > Mike
    >
    > --
    > Michael Winter
    > d (replace ".invalid" with ".uk")
     
    George Hester, Dec 5, 2003
    #3
    1. Advertising

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. Victor Bazarov
    Replies:
    25
    Views:
    964
    E. Robert Tisdale
    Mar 23, 2005
  2. Replies:
    9
    Views:
    1,008
  3. pereges
    Replies:
    7
    Views:
    459
    pereges
    Jun 1, 2008
  4. Ramon F Herrera
    Replies:
    8
    Views:
    508
    Pascal J. Bourguignon
    Sep 13, 2009
  5. deadpickle
    Replies:
    1
    Views:
    1,087
    Jens Thoms Toerring
    Nov 7, 2010
Loading...

Share This Page