Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > When is onSubmit fired?

Reply
Thread Tools

When is onSubmit fired?

 
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
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?

 
Reply With Quote
 
 
 
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
Sorry. Please ignore this question.

 
Reply With Quote
 
 
 
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
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>

 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      04-18-2006
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>


--

 
Reply With Quote
 
Ronaldo Junior
Guest
Posts: n/a
 
      04-18-2006

Water Cooler v2 wrote:
> 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()">

 
Reply With Quote
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
Thanks very much, Ronaldo.

 
Reply With Quote
 
Water Cooler v2
Guest
Posts: n/a
 
      04-18-2006
Thanks, Lee. I got that.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: onsubmit Event in aspx page. Mark Rae ASP .Net 0 08-17-2004 03:32 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej ASP .Net 0 06-04-2004 07:55 PM
Re: Add onSubmit To Form? =?Utf-8?B?Q3Jpc3RpYW4gQ2FybHNzb24=?= ASP .Net 2 05-27-2004 09:31 AM
need to have onsubmit event fire after server-side validation. usl2222@yahoo.com ASP .Net 3 02-25-2004 06:18 PM
Form-level onSubmit handler =?Utf-8?B?U25vd2JhbmsgSmlt?= ASP .Net 3 02-21-2004 06:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57