Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing an event object

Status
Not open for further replies.

minli98

IS-IT--Management
Aug 30, 2005
178
US
Hi,

I am learning how to use event in javascript and I have a basic question about passing an event object.

I know that the following is the basic method (for Firefox anyway)
Code:
<script>
function processEvent(e){

  alert(e.clientX);
}
</script>
<html>

<input type="button" value="Click" onclick="processEvent()">

</html>

But what if I want to pass another parameter, such a string? How would the following work?
Code:
<script>
function processEvent(str,e){

  alert(str + " " + e.clientX);
}
</script>
<html>

<input type="button" value="Click" onclick="processEvent(str)">

</html>
How can I make this code work? Thank you very much.

Regards,
Min
 
Sorry, the second code should read
Code:
<script>
function processEvent(str,e){

  alert(str + " " + e.clientX);
}
</script>
<html>

<input type="button" value="Click" onclick="processEvent('abc')">

</html>
 
I don't see how the first example would work for ff... In any case, one way is this (event keyword in the argument for firefox is immutable).
[tt]
<html>
<head>
<script>
function processEvent(e){
var evt=(e)?e:window.event;
alert(evt.clientX);
}
function processEvent2(str,e){
var evt=(e)?e:window.event;
alert(str + " " + evt.clientX);
}
</script>
</head>
<body>
<form>
<input type="button" value="Click" onclick="processEvent(event)">
<input type="button" value="Click2" onclick="processEvent2('abc',event)">
</form>
</body>
</html>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top