Question:
Guys I have the following select
in html.
<select name='busca' onChange='link()'>
<option value="1">OP1</option>
<option value="2">OP2</option>
<option value="3">OP3</option>
<option value="4">OP4</option>
</select>
I need to create a function in jQquey called link
where it takes the value of the select and loads a link, example: envia.php?op=1
Does anyone know how to do this?
Answer:
It is possible through jQuery's own change event to obtain the value:
$('select[name="busca"]').on("change",function(ev){
var linkEnviar = "envia.php?op=" + $(this).val();
console.log(linkEnviar);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="busca" name='busca'>
<option value="1">OP1</option>
<option value="2">OP2</option>
<option value="3">OP3</option>
<option value="4">OP4</option>
</select>