2x Submit Buttons To Action Different Url
Solution 2:
The following javascript function takes the URL of the target page and an associative array of name/values pairs and POSTs the data to the supplied URL by dynamically creating a form and then submitting it.
You can use instead of submit, two input buttons. On click of the buttons, u can mannualy change the action part to whatever you want, and then submit it.
var myForm = document.getElementById(formid);
myForm.action = to-wherever-u-want ;
myForm.submit() ;
Write two functions, with different actions, or write one function, determine which btn was pressd.
Your script was having some errors like that you called onsubmitform(), but you only have sumitform() in defenition. Pls take care of that too.
Solution 3:
Here's another option:
<form action="ThisActionIsReplacedInTheButtonOnclickEvent" method="POST" Name="MyForm" target="_blank" >
...
<inputtype="submit" name="MyBtn" value="do it" OnClick="document.forms['MyForm'].action = 'Destination1.aspx'" >
<inputtype="submit" name="MySecondBtn" value="do it different" OnClick="document.forms['MyForm'].action = 'Destination2.aspx'" >
BTW, IE doesn't seem to like inline js much, so you may have to break the form.action assignment out into a separate function like this:
<inputtype="submit"name="doitbtn"value="do it"OnClick="SetDest1()" /><SCRIPTLANGUAGE="JavaScript">functionSetDest1() {
document.forms["MyForm"].action = "Destination1.aspx";
}
functionSetDest2() {
document.forms["MyForm"].action = "Destination2.aspx";
}
</script>
Solution 4:
More simply:
<inputtype="submit" formaction="someaddress/whataver" value="Do X"/>
<inputtype="submit" formaction="/another/address" value="Do Y"/>
Solution 5:
Probably a tweaked version of the below code will help. I added the alerts for testing.
$('form[name="myform"] input[type="submit"]').click(function(event){
var $form = $('form[name="myform"]');
if($(this).val()=='Print'){
alert('print was pressed') ;
$form.attr('action','jbupdate.php');
}
else{
alert('save was pressed') ;
$form.attr('action','ppage.php');
}
});
//I added the following code just to check if the click handlers are called //before the form submission, The alert correctly shows the proper value.
$('form[name="myform"]').submit(function(event){
alert("form action : " + $(this).attr('action'));
//event.preventDefault();
});
You can play with the fiddle at http://jsfiddle.net/ryan_s/v4FtD/
Post a Comment for "2x Submit Buttons To Action Different Url"