Reputation: 415
i'm having a problem getting the selected value in jquery and stick it to the submit button. here's my code to better understand the problem.
As you can this is my Html form.
<form method = "get" action = "main/folder/">
<div id="select-vehicle">
<select>
</select>
</div>
<button type = "submit" value = "submit">TEST</button>
</form>
and here's my working jquery .
var workers = ["car1", "car2", "car3"];
for(var i=0; i< workers.length;i++)
{
//creates option tag
jQuery('<option/>', {
value: workers[i],
html: workers[i]
}).appendTo('#select-vehicle select'); //appends to select if parent div has id dropdown
}
Thank you very much!
Update
Whenever i get selected value i want to put that value end of form action
example : "main/folder/SelectedValue"
Upvotes: 0
Views: 100
Reputation: 20744
Try following:
$('button').click(function(event) {
event.preventDefault();
var value = $( "select" ).val();
$('form').attr('action', 'main/folder/' + value);
});
Add this code to your script and you will get selected value as a part of your form action attribute.
Upvotes: 2