Connecting Tech Pros Worldwide Forums | Help | Site Map

Form onsubmit is not working ..!!!!

dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#1: Sep 11 '08
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Untitled Document</title>
  6. <script type="text/javascript">
  7. function validate(){
  8.     alert('Yahoo...!!!');
  9.     return false;
  10. }
  11. </script>
  12. </head>
  13.  
  14. <body>
  15. <form onSubmit="return validate()">
  16. <input type=button value=submit onclick="this.form.submit()"/>
  17. </form>
  18. </body>
  19. </html>
  20.  

The function validate is not working ..!!!!!!!

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Sep 11 '08

re: Form onsubmit is not working ..!!!!


onsubmit occurs when a submit button is clicked. That's just a normal button.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,652
#3: Sep 11 '08

re: Form onsubmit is not working ..!!!!


a further note: "onsubmit" and "onSubmit" is not the same in XHTML. for events it is best to use only lower case attributes. (and IE can't properly handle XHTML)
Ferris's Avatar
Member
 
Join Date: Oct 2007
Location: Shanghai
Posts: 102
#4: Sep 12 '08

re: Form onsubmit is not working ..!!!!


you can use HTML submit element to post the form.

change
Expand|Select|Wrap|Line Numbers
  1. <input type=button value=submit onclick="this.form.submit()" />
into
Expand|Select|Wrap|Line Numbers
  1. <input type="submit" value="submit" />
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#5: Sep 12 '08

re: Form onsubmit is not working ..!!!!


Quote:

Originally Posted by acoder

onsubmit occurs when a submit button is clicked. That's just a normal button.

But Acoder i am submitting the form then why it shouldn't work ?
Ferris's Avatar
Member
 
Join Date: Oct 2007
Location: Shanghai
Posts: 102
#6: Sep 12 '08

re: Form onsubmit is not working ..!!!!


The submit method does not invoke the onsubmit event handler. Call the onsubmit event handler directly.

Expand|Select|Wrap|Line Numbers
  1.       <form onSubmit="return validate();">
  2.       <input type=button value=submit onclick="this.form.onsubmit();"/>
  3.       </form>
  4.  
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#7: Sep 12 '08

re: Form onsubmit is not working ..!!!!


Quote:

Originally Posted by dmjpro

But Acoder i am submitting the form then why it shouldn't work ?

I'll repeat what I said again highlighting the important points:

onsubmit occurs when a submit button is clicked. That's just a normal button. Calling the submit() method is not the same as clicking the submit button.
Reply