W3C home > Mailing lists > Public > www-html@w3.org > March 2005

Question about onsubmit HTML event and submit JS method

From: Rachael Hurd <Rachael.Hurd@cgi-ams.com>
Date: Wed, 23 Mar 2005 01:19:58 +0000
Message-ID: <6F34200C6828D446925E8B615EC7BE0386024E@KITKAT.ams.com>
To: <www-html@w3.org>
Can someone inform me about the background of the onsubmit HTML event
and submit() JS method? Reason I ask is because I notice when the submit
method is executed in JS, the onsubmit HTML event is not executed.  The
following code below was a piece of sample code I created to test this
theory (test-JSsubmit-finish.asp was just a page that contained 'Hello'
on it; nothing really important).

 

Was this functionality created on purpose by W3C (I'm assuming the
onsubmit HTML event came before the submit() method in JS)? If so, why?

 

Thank you.

 

Rachael Hurd

------------------------------------

[CODE]

<html>

<head>

<title>Testing Whether a Submit Event in JS runs the OnSubmit HTML
Event</title>

<script type="text/javascript">

 

function validateParameters()

{

    var x = document.forms.item(0).Number1.value;

    

    if (x != 3)

        {alert('SILLY! ' + x + ' is not equal to 3'); return false;}

    else

        {alert('The number you entered is equal to 3!'); return true;}

}

 

function checkBoxAndSubmit()

{

    document.forms.item(0).Checkbox1.checked=true;

    document.form01.submit();

}

 

</script>

<body>

    <h3>Testing Whether a Submit Event in JS runs the OnSubmit HTML
Event</h3>

    <br />

    <form name="form01" id="form01"
action="/Hospital/Tests/test-JSsubmit-finish.asp" method="post"
onsubmit="return validateParameters(4);">

        <input type="checkbox" name="Checkbox1" id="Checkbox1"
onclick="checkBoxAndSubmit();" />

        <input type="text" name="Number1" value="Enter a Number"/>

        <input type="submit" name="SubmitButton" value="Submit">

    </form>

</body>

</html>

[/CODE]
Received on Wednesday, 23 March 2005 03:13:32 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 27 March 2012 18:16:02 GMT