Is it possible, to generate an event on a text field?

S

stephen.cunliffe

Situation:

I have a few event handlers (not onclick) on a text box. The handlers
take in an event parameter to work some magic.

All the above works fine, but I have a desire/need, to "invoke" the
same handlers, but from another element (e.g. a separate button)

I know that someObject.click(); will actually work, but in my case, I
do not want to invoke the onclick handler.

Any Ideas?

PS I'd be happy to "fake" any of the following...

ondblclick
onkeydown
onkeyup
onkeypress

Cheers,
Steve
 
C

Craig Taylor

Situation:

I have a few event handlers (not onclick) on a text box. The handlers
take in an event parameter to work some magic.

All the above works fine, but I have a desire/need, to "invoke" the
same handlers, but from another element (e.g. a separate button)

I know that someObject.click(); will actually work, but in my case, I
do not want to invoke the onclick handler.

Any Ideas?

PS I'd be happy to "fake" any of the following...

ondblclick
onkeydown
onkeyup
onkeypress

Cheers,
Steve

Instead of 'faking' an event have you consdered doing the following:

in regular event handler call common_function()

and then call common_function()ality from both your event handler and
the other places that you need that behavior.

To answer your original question: In javascript inheritance is done by
making an object that looks like the original so you can always define
your own "event" with the properties that are referenced and then call
the events directly.

If you really want to go through the formal creation of an event object
then take a look at document.createEvent / document.createEventObject /
target.dispatchEvent / target.fireEvent.

- Craig Taylor
www.ctalkobt.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top