In: Computer Science
My Javascript code isn't working (when i press calculate button) - what's wrong with it ?
Car Rental
Enter Number of Rental Days:
Select Car Type:
onclick= "priceofcar = 50;"/> Compact
onclick= "priceofcar = 60;"/> Economy
onclick= "priceofcar = 70;"/> Intermediate
Select Loss Damage Waiver
onclick= "damagewaiver='yes'"/> Yes
onclick= "damagewaiver='no'"/> No
damagewaiver = boxDays.value * 25;}
else if (damagewaiver == No) {
damagewaiver = 0; }/>
Select Roadside Issues Coverage:
onclick= "issuescoverage='yes'"/> Yes
onclick= "issuescoverage='no'"/> No
issuescoverage = boxDays.value * 9;}
else if (issuescoverage == No) {
issuescoverage = 0; }/>
value = "Process"
onclick = "
myVariable = boxDays.value
boxrental = priceofcar * myVariable
boxoptional = damagewaiver + issuescoverage
boxsales = 0.7 * (boxoptional.value + boxrental.value)
boxtotal = boxsales.value + boxoptional.value +
boxrental.value"/>
Car Rental Price:
Optional Items:
Sales Tax:
Total Bill:
You are using onclick event in option tag to get the selected value. The onclick event wont supported with the option tag. so you didnt get the values for calculation and nothing displayed. You need to use the onchange function on select tag to get the selected value as follows: html
<span>select car type></span>
<select id="carbox" onchange="carbox();">
<option value="50">compact</option>
<option value="60" >economy</option>
<option value="70">intermediate</option>
</select>
and in your script write the code as follows:
<script type="text/javascript">
function carbox(){
var carvalue= document.getElementById("carbox").value;
alert(carvalue);
console.log(carvalue);
}
</script>
using the same for the remaining selection crieria. and do the calculation. Dont forget to add the script part inside header tag of your html .