I am trying to obtain the values that a user chooses from a fieldset
to later show a alert
that shows the price depending on the chosen option.
function formAlertCompra(){
var year = fieldset.getElementById('año').value;
var result_year=year*10;
alert(result_year);
return false;
}
<form ethod="post" onsubmit="formAlertCompra();"><fieldset data-role="fieldcontain" id="año">
<label for="año">Año:</label>
<select id="año_compra" name="año_compra">
<option>Seleccione Uno</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
</select>
<input type="submit" value="Register"> </fieldset>
</form>
However when selecting the year I am not getting any alert. What would be my mistake?
Before we start, let's go through some general observations:
method
, you missed an "m".onsubmit
, to avoid the behavior of sending the request there are several ways, one of them being the "return" of a variable as false.Fieldsets
do not have a defined value, according to the context, what you are looking for is the value that is within the displayed options, therefore the required value is delselect
.The following code solves your problem.