rempires Posted December 27, 2007 Share Posted December 27, 2007 Hi every, i have a javascript question regarding calling a function from a dynamically added html element. i put the element into a variable and i need to add an onchange call to it i know i can't get it to work in IE i haven't tested Firefox yet(my site keeps blocking me, stupid host... it thought i was flooding it because i accessed to so many times really fast.... so I'm running a IE specific proxy) anyway the code looks something like function addDDL() { var newSelectionDay = document.createElement('select'); newSelectionDay.setAttribute('id',DDLNum+"DDLDay"); newSelectionDay.setAttribute('name',DDLNum+"DDLDay"); newSelectionDay.onchange =dayChange(); //blah all we do ehre is add some options to that drop down lsit NewDiv.appendChild(newSelectionDay); } that doesn't work though, the error is obviously this line newSelectionDay.onchange =dayChange(); anyone know how i could add an event to a dynamically added element? thanks, john Quote Link to comment Share on other sites More sharing options...
mainewoods Posted December 28, 2007 Share Posted December 28, 2007 when you set an event like that, you don't use the parentheses: newSelectionDay.onchange =dayChange; // no ()'s Quote Link to comment Share on other sites More sharing options...
rempires Posted December 29, 2007 Author Share Posted December 29, 2007 thanks you very much, sorry for the delay in response i was outa town for a little bit, that did it... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.