开发者

Submitting two forms with one function does not work

I am facing a problem to submit two forms with one JavaScript function.

In that I have called one ajax file to check the username availability.

The forms are as below

<form action="abc.php" method="post" enctype="multipart/form-data" onsubmit="return isValid(this)" class="login_form" style="width:100%;开发者_StackOverflow社区">  

<form action="http://example.com" method="post" enctype="multipart/form-data" onsubmit="return isValid(this)" class="login_form" style="width:100%;" name="form1" id="form1">  

In isValid() function when I do

    alert ("hi");
    document.form1.submit();
    alert("bye");

Then it submitting the form1 else it does not.


You need to return a boolean value from the isValid() function since you're passing that value back to the onsubmit event of the forms:

Something like this should work for what you need:

function isValid() {
    // Do my validation here.
    return true; // or return false, depending on validation results.
}


You can try below code for that,

    var form1 = submit1();
    document.form1.submit();

    function submit1(){
      document.form2.submit();
      return true;
    }

In that submit1 function after submitting form you should return true then it will submit second form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜