passing variables?

G

George Hester

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?
 
M

Michael Winter

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:

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
 
G

George Hester

Hmm thanks Michael. I found a way around it:

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

But I like yours better.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top