Reputation: 11
I want to submit form(or setting value for action) with following details
<tr>
<td>
<label for="payment">Payment Mode:</label>
</td>
<td>
<select id="payment" name="payment" required="required">
<option value="">Select one...</option>
<option value="Cash">Cash</option>
<option value="Cheque">Cheque</option> `enter code here`
<option value="Draft">Draft</option>
</select>
</td>
</tr>
Upvotes: 0
Views: 432
Reputation: 3928
Here is a code snippet doing what you want:
$("#payment").on("change", function() {
if($(":selected", this).val() === "Cash") {
$("#YourFormId").attr("action", "a.php");
};
else {
$("#YourFormId").attr("action", "b.php");
}
$("#YourFormId").submit();
});
That will attach a change
event handler to your select
, check the value of the selected option and setting the correct action of your form according to your conditions
But you need to change the form selector for targetting the form you want to submit.
And a working jsfiddle
Upvotes: 0
Reputation: 278
I think best practice would be to always go to the same php file on submit, and there check if($_POST["payment"] == "cash")
.
Upvotes: 0