Click to See Complete Forum and Search --> : how to call javascript function on mouseclick
kalaid
July 20th, 2007, 04:48 AM
Hi
I want to call 2 different javascript function at a time on mouse click event.
Is there is any possibility to do this
PeejAvery
July 20th, 2007, 05:18 AM
Well, you can grab it in a tag. It is called onclick. Or you can set it with JavaScript.
<whatever_tag ... onclick="function(parameters)">
or
<script type="text/javascript">
document.onclick = function();
or
document.getElementById(...).onclick = function();
</script>
Shuja Ali
July 20th, 2007, 05:18 AM
Yes there is. Something like this <input type="text" id="text1" name="text1" onblur="function1(this.value); function2(this.value); function3(this.value); value = "Some Value">
andreasblixt
July 20th, 2007, 05:21 AM
To call two functions at once in the event, you can put them in an anonymous/lambda function (in element attributes you don't have to - it executes JavaScript if it's not a function name):
document.onclick = function () { func1(); func2(); };
// - or -
<a href="#" onclick="func1(); func2();">Link</a>
Note that in anonymous functions, the this keyword loses its scope. This can be solved using the call() method of the Function object:
element.onclick = function () { func1.call(element); func2.call(element); };
Using this with the above code will now refer to the element object.
kalaid
July 20th, 2007, 07:21 AM
Hi guy's
Thank's for u kind help
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.