By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

passing variables?

P: n/a
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
__________________________________
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #2

P: n/a
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" <M.******@blueyonder.co.invalid> wrote in message news:Xn*******************************@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
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.