468,301 Members | 1,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

Submission of a form using javascript....

108 100+
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(){
  4.  
  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">
  11.  
  12. <button onclick="chk()">Submit</button>
  13. </form>
  14. </body>
  15. </html>
  16.  
Any help willl be deeply appreciated...Thanks
Dec 14 '09 #1
4 1830
gits
5,390 Expert Mod 4TB
that is correct ... what do you want to achieve?

kind regards
Dec 14 '09 #2
phpuser123
108 100+
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
gits
5,390 Expert Mod 4TB
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
acoder
16,027 Expert Mod 8TB
...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.

Similar topics

2 posts views Thread by Logical | last post: by
6 posts views Thread by Charles Banas | last post: by
3 posts views Thread by Chris Smith | last post: by
6 posts views Thread by nick4soup | last post: by
6 posts views Thread by brettev | last post: by
6 posts views Thread by Oleg Konovalov | last post: by
1 post views Thread by rn5arn5a | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.