When is onSubmit fired?

W

Water Cooler v2

When does the onSubmit event occur? When does the JavaScript code we
write in this event get executed?

a. Before a page is posted to the server?
b. After the page is posted back, if posted back to itself, and
recieved from the server?
 
W

Water Cooler v2

OK, I am confused. I asked this question because the JavaScript
tutorial on w3schools says that onSubmit will cancel the submission if
the code it executes returns a value false. To test, I did this and yet
the page got posted to the target page successfully.


<HTML>
<SCRIPT>
function decision()
{
return false;
}
</SCRIPT>

<FORM name="frm" action="http://localhost/JavaScript/target.asp"
method="POST">
<INPUT type="text" name="txtWhatever" size="30" />
<INPUT type="submit" onSubmit="return decision()"/>
</FORM>
</HTML>




On target.asp, I just do:

<HTML>
<% Response.Write(Request.Form("txtWhatever")) %>
</HTML>
 
L

Lee

Water Cooler v2 said:
OK, I am confused. I asked this question because the JavaScript
tutorial on w3schools says that onSubmit will cancel the submission if
the code it executes returns a value false. To test, I did this and yet
the page got posted to the target page successfully.

ONSUBMIT is an attribute of the <form> element, not the submit button.


<HTML>
<head>
<title>demo</title>
<SCRIPT type="text/javascript">
function decision()
{
return false;
}
</SCRIPT>
</head>
<body>
<FORM name="frm"
onsubmit="return decision()"
action="http://localhost/JavaScript/target.asp"
method="POST">
<INPUT type="text" name="txtWhatever" size="30">
<INPUT type="submit">
</FORM>
</body>
</HTML>


--
 
R

Ronaldo Junior

Water said:
OK, I am confused. I asked this question because the JavaScript
tutorial on w3schools says that onSubmit will cancel the submission if
the code it executes returns a value false. To test, I did this and yet
the page got posted to the target page successfully.

[snip]
<INPUT type="submit" onSubmit="return decision()"/>

The function must be attached to the event of the FORM, not the submit
button.

<form [...] onsubmit="return decision()">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top