Reputation: 2897
I have a filter form where I want to change the action URL with jQuery.
<form id="filter_form" action="">
<div style=" bottom: 0; z-index: 1; width: calc(100% - 20px);">
<input id="filter_submit" type="submit" value="Suchen" data-theme="b" >
</div>
</form>
$("#filter_submit").on("click", function(e){
$("#filter_form").attr("action", "/test/").submit();
});
This unfortunatelly does not work. Is this even possible?
Upvotes: 0
Views: 151
Reputation: 3279
It works, you just have to cancel the original event. Example: https://jsfiddle.net/6oqy5jLz/
$('input').on('click', function(e) {
$('form').attr('action', '/bar').submit();
return false;
});
Upvotes: 1
Reputation: 488
Yes that is totally possible. And you are almost there.
I think you just have to prevent the form from submitting until you have changed the action.
Try this (not tested - but I think it should work):
$("#filter_submit").on("click", function(e){
e.preventDefault();
$("#filter_form").attr("action", "/test/").submit();
});
Upvotes: 0