DelphiFAQ Home Search:

Programmatically call the javascript onchange event handler


comments21 comments. Current rating: 4 stars (15 votes). Leave comments and/ or rate it.


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?


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)

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.


You are on page 1 of 2, other pages: [1] 2
2007-08-27, 13:24:04
anonymous from Westhoughton, United Kingdom  
Did you get an answer to this problem? If so can you tell me how to solve it, I'm struggling with the same issue.
2007-09-17, 16:47:52   (updated: 2007-09-17, 16:49:24)
anonymous from New Zealand  
hahahaha, ah, that cracks me up. But yeah, the answer is right. Just get hold of whatever DOM element it is you need, check that onchange is actually there (saving yourself from a possible exception) and then call onchange() on it.

E.g. you have a listbox with various regions in it and you want it to be set to 'Europe' (one of the values you loaded it with):

var regionDropdown = document.getElementById('region');
regionDropdown.value = 'Europe';
if (regionDropdown.onchange) regionDropdown.onchange();
2007-09-27, 03:32:02
[hidden] from India  
It seems the question was, if the onchange event is not specified in the HTML Tag and we only have javascript to tell that HTML Tag to fire onchange event, without mentioning it in the Tag itself ??
Can we later access that Tag and attach the onchange event to it ? If yes, Can you show us an example ?
2007-10-17, 06:37:28
from Brazil  
To attach a event into a control use this code

if (document.all) //IE6
field.detachEvent('onfocus', function);
else //Firefox
field.removeEventListener('onfocus', function, false);
2008-07-23, 23:45:13
anonymous from Vikhroli, India  
good one...
2008-09-24, 05:51:00
anonymous from New Delhi, India  
function check()
var dlist=document.getElementById('DropDownName');

2009-04-16, 00:03:46
anonymous from Delhi, India  
it is good
This image was also posted here:
Can I disable the Refresh button in Internet Explorer

2012-01-18, 08:43:03
I have some problems in creating web page using java script.i want to make a table box where i shown only a text box with 3 fields start field,end field and depth field.i want to allow only numeric in these fields.if any alphabetic chracter enter an alert box should appear which's allow only numbers enter. And i want also a button generate table if i click it a list of tables 2 to 10 should appear on web page.please help me in creatin this
2012-07-23, 22:42:46
anonymous from United States  
2013-07-21, 03:53:23
anonymous from India  

2013-08-14, 01:30:02
In fact, it greatly <a href=''>Mac Concealer</a> improves the bike's wholesale cosmetics braking acceleration cheap mac cosmetics an.. Read Automotive Adjusting Motorcycle Chains 02nd mac makeup online December 2005 Adjusting the chains authentic mac cosmetics is a grimy task. makeup wholesale Step 01: At the very first, use your concealer from your MAC make wholesale cosmetics up collection so the eye shadow mac makeup sale has something to stick to. You just need a bit use your finger to blend it over the whole eye lid and up to <a href=''>Mac makeup eyeliner</a> the brow. If you have any kind of skin problem then you should use cosmetics <a href=';wholesale mac makeup</a> that have discount mac makeup been tested for sensitive skin levels of mac makeup outlet chemicals. Packaging for Safe Cosmetics As cosmetic packaging plays an important role wholesale makeup cheap makeup in how the end-user interacts with your products, an attractive package is vital.
2015-01-30, 23:48:46
anonymous from Germany  
Hi!i would like to purchase a coulpe of items you have posted. How do I purchase? Also, josie maran argan oil (small) do you have 1 or 2 available?Thanks
2015-02-01, 14:40:26
The accident of finding this post has breigthned my day
2020-06-23, 18:25:52
Gus from Germany  
Magnificent beat ! I wish to apprentice even as you amend your web site,
how can i subscribe for a blog web site? The account aided me a acceptable deal.
I had been a little bit acquainted of this your broadcast offered vivid
clear idea
2020-06-28, 02:56:02
Elena from United Kingdom  
best place to buy cialis online reviews
You are on page 1 of 2, other pages: [1] 2



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: