Click to See Complete Forum and Search --> : How to check whether Left mouse button is pressed


sreenath205
May 30th, 2005, 06:26 AM
Hi

I have a button whose onmouseenter event calls a function say "foo",in foo
i need to check whether the left mouse button is pressed or not?


<html>
<script>

function foo(){
alert("came")

//How to check here whether the Left button is clicked??:eek:



}


</script>

<body>
<input type=button onmouseenter="foo()">

</body>
</html>




Thanks
Sreenath

Dr. Script
May 31st, 2005, 04:02 PM
Check the (event.button == 1) condition. From the body tag, the event.button == 1 onmousedown for left, and 0 for onclick for left in IE. This will return true if the left mous button was clicked. That is IE only. A universal solution would involve some other code. What is your audience?

sreenath205
June 1st, 2005, 12:55 AM
Hi

Thanks for the input but a problem exist

MSDN states that

"This(event.button")property is used with the onmousedown, onmouseup, and onmousemove events. For other events, it defaults to 0 regardless of the state of the mouse buttons."


Thanx
Sreenath

khp
June 1st, 2005, 01:05 AM
Indeed.

So what you do is setup an event handler for the onmousedown and onmouseup, which sets a variable in your script. Your other eventhandlers can then check this variable for the current mouse state.

Dr. Script
June 1st, 2005, 06:52 PM
Yes, for all your onmouseXXXX things, left mouse=0. For onclick however, the left mouse button returns 1.

Strange indeed.