I have initially created a form with a formid="blah" method="GET" action="blah.com". The form collects certain attributes and passes it on to blah.com on submit. Suppose i include a drop down/ radio buttons upon selection the form's action should be changed, i.e should submit to either of three separate forms. Could anyone explain how form action works? could i call function in the action attribute or any other attribute?
Asked
Active
Viewed 63 times
-1
-
You can call a js function with a "false button submit": `FalseSubmit` and in the submitForm function you've to get the data from where you want with `$('input#name').val();` and do whatever you want. – newpatriks Aug 21 '13 at 10:09
-
There is a large set of values to be collected, so i did not consider this, i wanted help if i could dynamically change the form action upon radio button selection. – Sravan Kumar Aug 21 '13 at 10:14
-
I think that is not the best polite solution, but you can change the action with `$('form').attr('action') = 'another/action.php';` – newpatriks Aug 21 '13 at 10:17
1 Answers
0
The action
attribute does not allow any script code.
However you can change the action value in the onchange event of your select inputs or via onsubmit of your form. Both of them allow you to use javascript code, which you can use to change the outcome of your form, depending on the input.
In case you use jQuery, you can easily get those with $('input#yourdropdownsname').val()
. The same holds for your form to change the action value.
See this javascript - change form action based on selection? for a full code example.