如何在formvalidation中使用多个按钮而不使用type =“submit”

时间:2022-09-25 15:26:39

I have implemented form validation, when i click on the submit button, whole page is getting refreshed.

我已经实现了表单验证,当我点击提交按钮时,整个页面都会刷新。

But my task is to submit the form and stay on that page only.

但我的任务是提交表单并仅保留在该页面上。

here is the below code, please suggest me how to Achieve that.

这是下面的代码,请建议我如何实现这一点。

enter code here
\\ Formvalidation code
     }
}).on('success.form.fv', function (e) {

    //e.preventDefault();
    //fv = $(e.target).data('formValidation'); // FormValidation instance\

    //fv.disableSubmitButtons(false);

    //InternaryTicketInvoiceSave();

    var $form = $(e.target),
   $button = $form.data('formValidation').getSubmitButton(),
   $statusField = $form.find('[name="status"]');

    switch ($button.attr('id')) {

        case 'btnTicketSave':
            InternaryTicketInvoiceSave();
            break;
        case 'UpdateStatus':
            InternaryTicketInvoiceSave();
            chnageSatatus();
            break;
       }


     });


     }
    //view code
     <form id="Iform" name="Iform" method="post">
        \\view code here
     </form>

2 个解决方案

#1


0  

use html 5 validation i.e sample example

使用html 5验证,即示例示例

 <form action="demo_form.asp" method="post">
      <input type="text" name="fname" required>
 <input type="email" name="email" required placeholder="Enter a valid email address">
      <input type="submit" value="Submit">
    </form>

detail http://www.the-art-of-web.com/html/html5-form-validation/

#2


0  

I was missing e.preventDefault();

我错过了e.preventDefault();

#1


0  

use html 5 validation i.e sample example

使用html 5验证,即示例示例

 <form action="demo_form.asp" method="post">
      <input type="text" name="fname" required>
 <input type="email" name="email" required placeholder="Enter a valid email address">
      <input type="submit" value="Submit">
    </form>

detail http://www.the-art-of-web.com/html/html5-form-validation/

#2


0  

I was missing e.preventDefault();

我错过了e.preventDefault();