Question about onsubmit HTML event and submit JS method

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 UTC