Submission of a form using javascript....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpuser123
    New Member
    • Dec 2009
    • 108

    Submission of a form using javascript....

    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 .....
    Code:
    <html>
    <script type="text/javascript">
    function chk(){
    
    	document.formname.submit();
    }
    </script>
    <body>
    <form name="formname" action="from.html" onsubmit="return false" method="get">
    <input type="text" name="firstbox">
    
    <button onclick="chk()">Submit</button>
    </form>
    </body>
    </html>
    Any help willl be deeply appreciated...T hanks
    Last edited by gits; Dec 14 '09, 06:16 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    that is correct ... what do you want to achieve?

    kind regards

    Comment

    • phpuser123
      New Member
      • Dec 2009
      • 108

      #3
      RE:Need help on sessions

      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?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        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

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          ...or avoid the use of chk() and make a call to your validation function onsubmit:
          Code:
          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().

          Comment

          Working...