2
I have an excerpt of code where I wish to pick up the value of option
selected, with Javascript, and give a alert
with that value. However, every time he gives the value as undefined
. I made a line to put in a input
also, just to test, and it didn’t work.
Here is the code:
$("select[name='estado']").change(function() {
var estado = document.getElementsByTagName("estado").value;
document.getElementById("teste").setAttribute("value", estado);
alert('estado ' + estado);
});
<select id="txt-model" class="field-50" name="estado">
<option value="">Selecione um Estado</option>
<option value="AC">Acre</option>
<option value="AL">Alagoas</option>
<option value="AP">Amapá</option>
//... O resto dos estados
</select>
<input type="text" id="teste" name="teste">
use $(this). val() to get the value in the selector.
– N. Dias