document.createEvent parameter for change event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #1

    document.createEvent parameter for change event

    What do I pass as a parameter to the document.create Event 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.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ... here is a short example for the usage:

    Code:
    <html>
        <head>
            <script type="text/javascript">
                function raiseEvent() {
                    var ele = document.getElementById('myNode');
                    ele.onchange = function() { alert(this.value); };
    
                    var e = document.createEvent('HTMLEvents');
                    e.initEvent('change', true, true);
    
                    ele.dispatchEvent(e);
                }
            </script>
        </head>
        <body onload="raiseEvent();">
            <input type="text" value="bar" id="myNode" />
        </body>
    </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.initUIEve nt() method is to be used and you could pass more params ...

    kind regards
    gits

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      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<<

      Comment

      Working...