DelphiFAQ Home Search:
General :: Web publishing :: JavaScript :: Events
Questions, answers and code examples dealing with javascript event handlers.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Programmatically call the javascript onchange event handler

Question:

My javascript function updates an array of controls (listboxes) and makes selections. I would like to have the onchange event handler fire after each change but it does not get executed. How can I programatically call the handler?

Answer:

There is no special trick to this other than checking first if the event handler for the given control is actually defined - to help avoid a runtime error.

if (document.form1.listbox1.onchange)
  document.form1.listbox1.onchange();

Another observation I made is that some HTML editors will generate HTML like this:

<select .. onChange=myFunction()>

Note that the event name is in mixed case here (capitalized C) but the name of the property has to be written all lower case as shown at the top.


Generated 16:01:58 on Nov 12, 2018