Hi, guys. Can I ask this as well?
I made this script last week. I was pretty happy about it until I found horrible error about null value entity.
My exercise was:
quote:
User can buy three different types of tickets. Standard is $50. Clsoe up is $70. And back stage is $250. User can choose ticket type through dropdown box.
Problem is:
It works only when user put number of ticket into *all* three boxes. Otherwise total box shows just Null!!! I don't know why this happens.....Could you give me tips, please???
Here is my code:
code:
<html>
<head>
<script type="text/javascript">
function cal(){
if(parseInt(form1.sta.value)<0){
alert("Re-enter, pleaes");
return false;
}
if(parseInt(form1.clo.value)<0){
alert("Re-enter, pleaes");
return false;
}
if(parseInt(form1.bac.value)<0){
alert("Re-enter, pleaes");
return false;
}
switch(form1.type.selectedIndex){
case 0: form1.sub1.value=parseInt(form1.sta.value)*50;
break
case 1: form1.sub1.value=parseInt(form1.sta.value)*70;
break
case 2: form1.sub1.value=parseInt(form1.sta.value)*250;
break
}
switch(form1.type1.selectedIndex){
case 0: form1.sub2.value=parseInt(form1.clo.value)*50;
break
case 1: form1.sub2.value=parseInt(form1.clo.value)*70;
break
case 2: form1.sub2.value=parseInt(form1.clo.value)*250;
break
}
switch(form1.type2.selectedIndex){
case 0: form1.sub3.value=parseInt(form1.bac.value)*50;
break
case 1: form1.sub3.value=parseInt(form1.bac.value)*70;
break
case 2: form1.sub3.value=parseInt(form1.bac.value)*250;
break
}
form1.total.value=parseInt(form1.sub1.value)+parseInt(form1.sub2.value)+parseInt(form1.sub3.value);
if(parseInt(form1.total.value) > 1000){
form1.total.value=parseInt(form1.total.value)*0.9+5
}else if(parseInt(form1.total.value) > 500){
form1.total.value=parseInt(form1.total.value)*0.95+5
}else{
form1.total.value=parseInt(form1.total.value)+5
}
}
</script>
</head>
<body>
<form name="form1">
<select name="type">
<option>Standard</option>
<option>Clse-Up</option>
<option>Back Stage</option>
</select>
<input type="text" name="sta" size="3"/>
$<input type="text" name="sub1" size="5" /><br />
<select name="type1">
<option>Standard</option>
<option>Clse-Up</option>
<option>Back Stage</option>
</select>
<input type="text" name="clo" size="3"/>
$<input type="text" name="sub2" size="5" /><br />
<select name="type2">
<option>Standard</option>
<option>Clse-Up</option>
<option>Back Stage</option>
</select>
<input type="text" name="bac" size="3"/>
$<input type="text" name="sub3" size="5" /><br />
<p><input type="button" value="Calculate" onClick="cal()"/>
<input type="reset" value="Reset" /></p>
<p>Total cost is: $<input type="text" name="total" size="8"/></p>
</form>
</body>
</html>
thanks for reading this.
Hiroki Kozai