Tech Off Post

Single Post Permalink

View Thread: More ECMAScript fun!
  • User profile image
    Sven Groot

    Maurits wrote:
    I see, the default action for a <button> is to submit the form!  That's nasty.

    If you make your onclick functions return false, would that cancel the click, and therefore the submit?

    No. There's a way to cancel the default action from script, but unfortunately it's not that simple. Actually, there's two ways: the standard way and the IE way. The standards way you have to call event.preventDefault(), the IE way you have to set event.returnValue = false. I usually do this:

    if( typeof(event.preventDefault) == "function" )
       event.returnValue = false;