By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,628 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,628 IT Pros & Developers. It's quick & easy.

Is that possible to call onclick from JS ?

P: n/a
abs
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='myFunction()'> 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
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"abs" <ab**********@alpha.net.pl> wrote in message
news:d3**********@news.onet.pl...
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='myFunction()'> 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

So you don't want:

<script type="text/javascript">
myFunction();
</script>

And you don't want an "onclick" to invoke it.

An function is invoked -- how else would you invoke it?!
Jul 23 '05 #2

P: n/a
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='myFunction()'> 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
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.