Reputation: 33
how to change action of form using javascript and using onsubmit button . i tried to write this but nothing happen and page wont change although i change the action form using js in jsp file is there way to debug js
How do I change a form's action attribute right after clicking the submit button?
<form id="cust" name="cust" method="post" onsubmit="return myAction()">
<table style="with: 50%">
<tr>
<td>a</td>
<td><input type="date" name="departureDate" placeholder="yyyy-mm-dd" value="">
</td>
</tr>
<tr>
<td>b</td>
<td>
<select name="comeFrom">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</select>
</td>
</tr>
</table>
<input type="submit" name="io" value="next" />
</form>
Upvotes: 0
Views: 957
Reputation: 13110
This is as simple as it can get. Listen for the submit event and in the callback function change the action.
document.forms.form01.addEventListener('submit', e => {
e.target.action = 'page02';
});
<form name="form01" action="page01" method="post">
<button>Submit</button>
</form>
Upvotes: 1