1. Registered User
Join Date
Sep 2013
Posts
1

## help with javascript Calculations radio box

Can anyone help me
I trying to do a piece of coding which has two groups of radio button in them one that selects the water system and the time it take and the other one selects which soil type and how many time to water the soil for. I al so have a checked box if there are large plants to be watered which added and extra 1.5 time on
I need to validate also if the radio button have been checked or not.
I am have problems working on the calculation being a newbie at all this JavaScript thing

<!doctype html>
<html>
<meta charset="utf-8">
<title>Home Gardening Watering guide</title>
<script>

//Check the users responses and calculate the fare
function fareCalc() {
var checkbox; // A checkbox
var watersystem = 0; //The number of the fare selected
var soilType = 0; //The number of the seat
var wateringTime = 0; //Total cost of the fare

//Find the valueof the waater system button
for (var i = 1; i <=4; i++) {
if (radioButton1.checked == false ) {
}
else
}

//Check if there are large plant involed
for (var i = 1; i <=1; i++) {
checkbox = document.getElementById("trees");
if (checkbox.checked == true) {
trees = "1.5";
}
if (checkbox.checked == false) {
trees = "0";
}
}
// Get the selected soil type
for (var i = 1; i <=3; i++) {
}
}
// alert if no seating class selected
if (soilType == 0) {
}

//Display total cost of selected fare
wateringTime = watersystem * trees * soilType ;
//Round to the nearest number
wateringTime = Math.round(wateringTime);
//Turn string into Integer
wateringTime = parseInt(wateringTime);

//Display total cost of flight
alert ("The cost of the flight is \$ " + wateringTime);
}
</script>

<body>
<h1>Gotham Airlines Fare Calculator</h1>
<p>Complete the form below to calculate the cost of your flight.</p>
<form>
<p>Route:<br>
<input type="radio" id="water1" name="water" value="6"> <label for="water1">Jet Spray </label><br>
<input type="radio" id="water2" name="water" value="10"><label for="water2">Sprinkler </label><br>
<input type="radio" id="water3" name="water" value="17"><label for="water3">Mini Sprinkler</label><br>
<input type="radio" id="water4" name="water" value="50"><label for="water4">Dripper </label><br>

</p>
<p>Seating:<br>
<input type="radio" id="soil1" name="soil" value="2"><label for="seat1">Sand</label><br>
<input type="radio" id="soil2" name="soil" value="1.5"><label for="seat2">Loam</label><br>
<input type="radio" id="soil3" name="soil" value="1"><label for="seat3">Clay</label></p>
<p><input type="submit" value="Calculate" onClick="fareCalc();"> <input type="reset" ></p>

</form>
</body>
</html>

2. Super Moderator
Join Date
Jun 2004
Location
Portsmouth UK
Posts
2,709
Code:
```<!doctype html>
<html>
<meta charset="utf-8">
<title>Home Gardening Watering guide</title>
<script>

//Check the users responses and calculate the fare
function fareCalc(frm) {
break;
}
}
if (!w){
mess.push('Click Water');
}
break;
}
}
if (!s){
mess.push('Click Soil');
}
if (s&&w){
t=s*w;
}
return false; // change to true to submit the form
}
return false;
}
</script>

<body>
<form onsubmit="return fareCalc(this);">
<p>Water Type:<br>
<input type="radio" name="water" value="6"> <label for="water1">Jet Spray </label><br>
<input type="radio" name="water" value="10"><label for="water2">Sprinkler </label><br>
<input type="radio" name="water" value="17"><label for="water3">Mini Sprinkler</label><br>
<input type="radio" name="water" value="50"><label for="water4">Dripper </label><br>

</p>
<p>Soil Type:<br>
<input type="checkbox" name="large" value="1.5" /> Large Plants
<p><input type="submit" value="Calculate"  <input type="reset" ></p>

</form>
</body>
</html>```