hi guys
this is probably real simple to you but im a newbie …if you look at my code at the discount part of the script, if no radio button is selected it doesnt seem to be bringing up my alert but instead carrys on with the calculation. your help is appreciated!!
thanks, marty.
<html>
<head>
<title>New Zealand Holiday Price Calculator</title>
<script language=”JavaScript”>
<!–
function tourType() //this is the fucntion that will calculate the selected fields in the form
{
var payment=0; //declare the variable payment to be equal to zero
if (document.info_form.optlist.selectedIndex == 0) //this checks that an option has been slected from the dropdown box
window.alert(“You have not selected a tour type”); //if not this alert will show
else
if (document.info_form.optlist.selectedIndex == 1)
{
payment=1500; //if option 1 is selected payment becomes 1500
}
else
if (document.info_form.optlist.selectedIndex == 2)
{
payment=1600; //if option 2 is selected payment becomes 1600
}
else
if (document.info_form.optlist.selectedIndex == 3)
{
payment=1750; //if option 3 is selected payment becomes 1750
}
else
if (document.info_form.optlist.selectedIndex == 4)
{
payment=2100; //if option 4 is selected payment becomes 2100
}
discount=0; //the variable discount is set to zero
for (var i=0; i<=3; i++) // this for loop is checks to see which radio button was selected by the user
if (document.info_form.dateDiscount[i].checked)
{
discount=document.info_form.dateDiscount[i].value; //dependant on the radio button slected, its value, stated in the html
code becomes the integer for the variable discount
}
else
if (document.info_form.dateDiscount == 0)
{
alert(“No date selected”);
}
var airtravel=0; //this is the variable for the checkbox
if (document.info_form.airfare.checked) //if the checkbox named “airfare” has been checked
{
airtravel=400; //then the variable becomes 400
}
var total=payment+airtravel-discount; //a new variable is stated here. it adds all the values from the previous variables
alert(“The approximate cost is $”+total); //an alert box is then shown to show the user the cost of the holiday
}
//–>
</script>
</head>
<body>
<font size=”6″><b>New Zealand Price Holiday Calculator</b>
<p>
<font size=”3″>
Complete the form below to calculate the cost of your New Zealand Holiday.
<p>
<form name=”info_form”>
Tour Type:
<select name=”optlist”>
<option>
<option>12-day New Zealand Escape Tour
<option>14-day New Zealand Panorama Tour
<option>15-day New Zealand South to North Tour
<option>17-day Best of New Zealand Tour
</select>
<p>
Payment date:<br>
<input type=”radio” name=”dateDiscount” value=”200″>Before 1st August 2005
<br>
<input type=”radio” name=”dateDiscount” value=”150″>Between 1st and 31st August 2005
<br>
<input type=”radio” name=”dateDiscount” value=”100″>Between 1st and 30th September 2005
<br>
<input type=”radio” name=”dateDiscount” value=”0″>After 30th September 2005
<p>
Click here if you want to include an airfare from Sydney, Brisbane or Melbourne: <input type=”checkbox” name=”airfare”>
<p>
<input type=”submit” value=”Calculate” onclick=”tourType();”> <input type=”reset” value=”Reset”>
</body>
</html>