开发者

Form Submission to two different location

I have a list o开发者_StackOverflowf check boxes. I want to check them and submit.

  1. I should be able to check 2 entries and and submit it to compare.php
  2. or i should be able to check one and send it to insert.php.

is this possible ?


Yes, you definitely can, though perhaps the logic to determine the flow should be on the server side (clients have a habit of sending bad things, which you can deal with on the server-side).

I would use jQuery, though native Javascript would work fine (it'd be more complicated, though).

I'd do something like:

<form id="myForm"></form>
<script type="text/javscript">
$('#myForm').submit(function() {
  // Look at form inputs here and set the form action accordingly.
  // Note: 'this' refers to the form DOM element.
  this.setAttribute('action', 'myurl.php');
});
</script>


you can create a frame and do that.


You can use AJAX to do this. Have you form action point to a JS function that would do something like:

if(checkbox1.checked==1 && checkbox2.checked==1) {
     //ajax request to compare.php
} else if(checkbox1.checked==1 || checkbox2.checked==1) {
     //ajax request to insert.php
}


you can do this by using AJAX form submit

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜