I am trying to create a Unit Converter. My Idea is to have a select box at the top to select Length/Temp etc. which will populate the two select boxes below with appropriate units. The below code should Work only for Milimieters to Milimeter, Meters and Kilometers. It should show the calculated value in the alert box that appears when go is pressed..
What I was able to determine by using firebug is that the script doesn't falls into the switch block and the calculations never happen AND I am unable to determine WHY? I will be grateful if some one can explain it to me. I am fairly new to javascript, this is just my first app.
For a good view how the site works: http://saad749.freeoda.com/MetricConversions/conversions.html
You can view the source code in firefox for the whole site. Thanks a lot. The major part of code is given below:
function calculate()
{
var e;
var uniti;
var unito;
var vali;
var valo;
e = document.form1.entity.options[document.form1.entity.selectedIndex].value;
uniti = document.form1.Iunit.options[document.form1.Iunit.selectedIndex].value;
unito = document.form1.Ounit.options[document.form1.Ounit.selectedIndex].value;
vali = document.form1.Iamount.value;
valo = document.form1.Oamount.value;
switch (e)
{
case 1:
switch(uniti)
{
case 1:
switch(unito)
{
case 1:
valo = vali*1;
break;
case 2:
valo = vali*100;
break;
case 3:
valo = vali*1000;
break;
}
break;
}
break;
}
alert(e + "\t" + uniti + "\t" + unito + "\t" + vali + "\t" + valo);
}
<input type="submit" name="go" id="go" value="Go !" onclick="calculate();"/>