I am pretty new in JavaScript and jQuery and I have the following problem trying to retrieve the value related to the selected option of a select.
So, into my page I have:
<select id="selAttivitaSelezionata" class="form-control valid" name="selAttivita" aria-invalid="false">
<option value="valida">Valida Progetto</option>
<option value="invalida">Rimuovi Validazione</option>
</select>
then I have the following jQuery code that is performed every time that the user select an option inside the previous select:
$("#selAttivitaSelezionata").change(function() {
//alert("TIPOLOGIA PROGETTO CAMBIATA");
var sel = $("#selAttivitaSelezionata");
var val = sel.value;
alert(val);
$("#statoProgettoLabel").hide();
$("#selStatoProgetto").hide();
});
So, as you can see first I select the select object in the DOM having id="selAttivitaSelezionata" and then I try to obtain the selected value by sel.value, then I print it into an alert popup
The problem is that the alert is empty. Using the FireBug debugger I see that the sel variable is correctly initialized but the val variable is undefined as value obtained by sel.value.
Why? What am I missing? How can I obtain the value of the value attribute (valida or invalida)?