#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    8
    Rep Power
    0

    Executing submit() method of the form does't fire form's onsubmit() event


    I have the following problem, I am submitting form from javascript using
    myForm.submit();
    but that would not fire form's onSubmit event.

    Example:

    <form name=frm action="test3.asp" onsubmit="alert('onSubmit()')">
    <input type=submit value="Submit">
    </form>

    <button onclick="frm.submit()">JS Submit</button>

    First submit button would fire onSubmit event, while second would not.

    Does anyone know why?
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    You actually have the wrong forum, but I found the anwser anyway. Per MSDN:
    The submit method does not invoke the onsubmit event handler. Call the onsubmit event handler directly. When using Microsoft® Internet Explorer 5.5 and later, you can call the fireEvent method with a value of onsubmit in the sEvent parameter.
    http://msdn.microsoft.com/library/de...ods/submit.asp

    This works:
    Code:
    <form name=frm onsubmit="alert('onSubmit()')">
    <input type=submit value="Submit">
    </form>
    <button onclick="frm.fireEvent('onsubmit'); frm.submit()">JS Submit</button>
    Last edited by Nemi; February 20th, 2003 at 08:14 PM.

IMN logo majestic logo threadwatch logo seochat tools logo