By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

Submission of a form using javascript....

P: 108
I want to submit my form using javascript but the prob I am facing here is when using this method,the form is being submitted irrespective of the return value of onsubmit .My script is .....
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <script type="text/javascript">
  3. function chk(){
  5.     document.formname.submit();
  6. }
  7. </script>
  8. <body>
  9. <form name="formname" action="from.html" onsubmit="return false" method="get">
  10. <input type="text" name="firstbox">
  12. <button onclick="chk()">Submit</button>
  13. </form>
  14. </body>
  15. </html>
Any help willl be deeply appreciated...Thanks
Dec 14 '09 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 5K+
P: 5,371
that is correct ... what do you want to achieve?

kind regards
Dec 14 '09 #2

P: 108
the prob I am facing is that although the onsubmit has a return value of false,it is being submitted.When I am using <input type="submit" value="submit"> to submit the form,the form is nt submitted since the onsubmit holds a value of false..Why this difference? And what cn I do so that the form is not submitted with the javascript?
Dec 15 '09 #3

Expert Mod 5K+
P: 5,371
just don't call the submit()-method when the form shouldn't be submitted ... a simple if-else would do the job in your chk()-function

kind regards
Dec 15 '09 #4

Expert Mod 15k+
P: 16,027
...or avoid the use of chk() and make a call to your validation function onsubmit:
Expand|Select|Wrap|Line Numbers
  1. onsubmit="return validate()"
Also note that button by default is a submit button. Perhaps you meant to use an input button (input type="button"). Alternatively, set the button type to "button".

One more thing: the submit is prevented when the user clicks on the submit button, not when the form is submitted using JavaScript via submit().
Dec 21 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.