简体   繁体   中英

Can we have more than one submit type button in one form?

I need to implement validation for a form but by two submit buttons?

Can we do change the 'Type' from jQuery so that it can work perfectly as i want:)

If you are talking about client-side validation you can use JavaScript to make different buttons post to different locations (these locations can be different to validate it in more than one way on the server side) eg

<form name="someForm1" id="someForm1" method="POST">
.
.
.


<input type="button" name="button1" id="button1" onclick="javascript:post1();"/>
<input type="button" name="button2" id="button2" onclick="javascript:post2();"/>
</form>

Then make post1 implement one type of client-side validation ( validate1() ) and post2 ( validate2() ) the other approach. You can even use JavaScript to post to different URLs. An example of how this can be done is:

function post1()
{
  var form1=document.forms['someForm1'];
  form1.action="form1.aspx";
  if(validate1())
  {
     form1.submit();
  }
  else
  {
     invalid1();
  }    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM