0
Good evening, I would need the user to choose how many classes you want in select and then the system will calculate the value and put in the other input, I don’t know where I’m going wrong if you can help me
<script type="text/javascript">
// classe 1 classe
var valorDaMarca = parseFloat('1855.80');
// demais classes
var valorDasDemaisClasses = parseFloat('805.20');
var classe = document.getElementById("classes").value
function valorTotal(){
switch (classe) {
case 1:
document.getElementById("pfn_vlr_total").value = valorDaMarca;
break;
case 2:
document.getElementById("pfn_vlr_total").value = valorDaMarca + valorDasDemaisClasses;
break;
}
}
</script>
<html>
<select id="classes" name="classes" onchange="valorTotal();">
<option value="1">1 Classe </option>
<option value="2">2 Classes</option>
<option value="3">3 Classes</option>
<option value="4">4 Classes</option>
<option value="5">5 Classes</option>
<option value="6">6 Classes</option>
</select>
<input id="pfn_vlr_total" name="pfn_vlr_total" readonly ="readonly" type="text" class="total text-center" value="0,00" required>
I’ll leave picture of something similar but with radio buttons
Thank you for your attention and help
you need to read the value of the class within the "valueTotal" function. when read the value had not yet been chosen, and is using an outdated value, since the event is
onchange
, that is, if changed need read again– Ricardo Pontual
I get your point but I don’t know how to read it again do you have any idea? For me how is onchange every time I change the option should update the value
– Prozyn
of course not, you read the value
value
at a certain point, it won’t automatically update, and you wanted to keep the original value? how to do? only move the line inside the Function to read the value when it changes– Ricardo Pontual