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

document.createEvent parameter for change event

Expert Mod 5K+
P: 9,731
What do I pass as a parameter to the document.createEvent method to issue a "change" event?

I went through each of them listed there and the only one I couldn't get to work was the mutation one.
Mar 5 '09 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 5,390
hi ... here is a short example for the usage:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.             function raiseEvent() {
  5.                 var ele = document.getElementById('myNode');
  6.                 ele.onchange = function() { alert(this.value); };
  8.                 var e = document.createEvent('HTMLEvents');
  9.                 e.initEvent('change', true, true);
  11.                 ele.dispatchEvent(e);
  12.             }
  13.         </script>
  14.     </head>
  15.     <body onload="raiseEvent();">
  16.         <input type="text" value="bar" id="myNode" />
  17.     </body>
  18. </html>
i never used it before and the documentation is quite ... lets say ... short ;) ... but the above example works. it would even work with UIEvents, where the event.initUIEvent() method is to be used and you could pass more params ...

kind regards
Mar 6 '09 #2

Expert Mod 5K+
P: 9,731
Most of the time it's my JavaScript that's not working, but in this case it was my .NET code!

I forgot to indicate that the <select> should post back to the server when its selected index changed..... and that's why it wasn't getting back to the server after raising the event!

>>hangs head in shame<<
Mar 6 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.