Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old September 11th, 2008, 06:23 PM
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Age: 25
Posts: 2,164
Default Form onsubmit is not working ..!!!!

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 ..!!!!!!!
Reply
  #2  
Old September 11th, 2008, 06:53 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,964
Default

onsubmit occurs when a submit button is clicked. That's just a normal button.
Reply
  #3  
Old September 11th, 2008, 07:49 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Age: 31
Posts: 894
Default

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)
Reply
  #4  
Old September 12th, 2008, 05:43 AM
Ferris's Avatar
Member
 
Join Date: Oct 2007
Location: Shanghai
Age: 22
Posts: 102
Default

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" />
Reply
  #5  
Old September 12th, 2008, 06:31 AM
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Age: 25
Posts: 2,164
Default

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 ?
Reply
  #6  
Old September 12th, 2008, 06:54 AM
Ferris's Avatar
Member
 
Join Date: Oct 2007
Location: Shanghai
Age: 22
Posts: 102
Default

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.  
Reply
  #7  
Old September 12th, 2008, 12:17 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,964
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.