Reputation: 331
So I've got myself a form here shown below; I'm trying to change the form's action link based on the selection. However it's not really working for me.
<form action="">
<select id="location">
<option value="http://www.google.com/php:id=384733">New York</option>
<option value="http://www.google.com/php:id=384734">Georgia</option>
</select>
<input type="submit" value="Submit">
</form>
$("#location").change(function() {
var action = $(this).val();
$("form").attr("action")};
});
)};
There's more then just the two states, I'll have all states but for this example I've listed two. the value would be the url with different ID numbers as shown above.
In the end, if I selected New York the action in the form code would get updated and show something similar to this;
<form action="http://www.google.com/php:id=384733">
Upvotes: 1
Views: 1097
Reputation: 504
There seems you have a typo in your javascript, check this:
$("#location").change(function() {
var action = $(this).val();
$("form").attr("action",action);
});
Upvotes: 0
Reputation: 318182
You're almost there, just a few syntax errors, and you're never setting the attribute
$("#location").on('change', function() {
$(this.form).attr("action", this.value);
});
Upvotes: 2