abs wrote:
Hi all.
Is that possible to call the onclick, onchange or other event from JS ? I
mean how to make the browser think that user clicked the element (onclick
event) ? Eg. I have <element onclick='myFunc tion()'> and I don't want to
call the myFunction() by writing its name in the code but I want to call the
onclick event without clicking :) I don't know how to explain it better, I
hope you know what I mean.
Best regards,
ABS
If I understand you, you want to simulate the click by triggering an
"onclick" event based on something else. You want the user to still be
able to click on the button manually, but want the option of faking the
click after they do 2 or 3 other things.
If the above is correct, you want the click() method. All you need to do
is use the DOM address of the element in question and call:
element.click() ;
Keep in mind that this doesn't work for all form elements, but does work
for the ones you *should* be thinking about for this purpose: buttons,
checkboxes, radio buttons, resets, submits and selects.
This method is part of the set of methods that you can use to simulate
most user interactions and includes: blur(), focus(), select() as well
as click().
Once you go down this road, be careful of infinite loops in your code
where you trigger an event that triggers an event, etc.
J Wynia
Myriad Intellect, Inc.
www.myriadintellect.com