Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<HTML>
<HEAD>
<TITLE> "CALCULATE FUEL COST" </TITLE>
<SCRIPT LANGUAGE = "JavaScript">
function fuelCalculator() {
var costpergallon;
costpergallon= (document.form1.ppg.value / (100 - document.form1.my_select.value))*100 / 12 // document.form1.mpg.value;
document.form1.cpg.value = costpergallon;
//document.write(costpergallon);
}
</script>
</head>
<Body>
Sampath Bank
<form name ="form1">
Amount :<input type="text" name="ppg" value=0 /> </br>
Installments : <select id="my_select" name="my_select">
  <option value="9.25">3</option>
  <option value="10.75">6</option>
  <option value="13.75">12</option>
  <option value="20.25">24</option>
  <option value="24.75">36</option>
  <option value="48">48</option>
  <option value="60">60</option>
</select> </br>
<input type="text" name="mpg" value=0 /> </br>
<input type="text" name="Airfare" value=0 /> </br>
<input type="text" name="AirlineTax" value=0 /> </br>
<input type="text" name="HotelExp" value=0 /> </br>
<input type="text" name="ToursExp" value=0 /> </br>
<input type="text" name="cpg" value=0 /> </br>
<input type= "button" value="Calculate" onclick="fuelCalculator();" />
</form>
</body>
</html>



this is my code?

i want to put if else condition.

if (my_select == 9.25){
var val1= 12;
var total;
total = val1*9.25 }

else
if (my_select == 10.75){
var val1= 6;
var total;
total = val1*10.75 }
}

How can i do that?
Posted
Updated 18-Feb-15 16:23pm
v4
Comments
Suvendu Shekhar Giri 18-Feb-15 6:28am    
Seems, you know what you want to do, then what is the issue doing this?

1 solution

This is not a final solution,
as it is not clear what you want to calculate,
but shall show you how to get the values from the select tag:
C#
function fuelCalculator() {
    var input = document.getElementById('my_select');
    var value = input.options[input.selectedIndex].value;

    alert(value);

    var total = value * 12;

    alert(total);
}


Hopefully this will help you to proceed!

This does not use JQuery but plain javascript.
Below you find a good resource for learning it:
http://www.w3schools.com/js/default.asp[^]
 
Share this answer
 
Comments
Hemas Ilearn 18-Feb-15 22:26pm    
i want if else conditions?

because if(input.selectedIndex==13.75){
var total = 13.75*12
}
else(input.selectedIndex==10.75){
var total = 10.75*6
}

like that.

please it will be very helpful for me if you can solve this issue?
i don't have much experience in html as well
TheRealSteveJudge 19-Feb-15 2:44am    
There is no need for if/else statements here.
Please try the suggested function.
It just gets the selected value which is in range 9.25 ... 60.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900