Results 1 to 2 of 2

Thread: [RESOLVED] New to JavaScript totally stumped

  1. #1
    Join Date
    Sep 2013

    resolved [RESOLVED] New to JavaScript totally stumped

    Hi everyone

    I am trying to build a JavaScript form using radio buttons and trying to achieve a
    watering time calculator using 2 sets of information.
    1. 4 different systems
    2. 3 different types

    All systems + type1 = the variable totals represented below
    All systems + type2 = are multiplied by 2
    All systems + type 3 = are multiplied by 3.5
    If the 'largeplants' check box is selected the total needs to be multiplied by 1.5

    The calculateTime function needs to calculate the watering time on click & display an alert box stating the watering time
    & The reset button needs to reset the radio buttons.

    <!doctype html>
    <meta charset="utf-8">
    <title>Perfect Watering Results</title>


    //Calculate Watering Time for Plants
    function calculateTime (){
    var radioButton //A radio button
    var selectedAnswer = 0; //The number of the selected answer
    var system1 = 6; //watering time for sand with jetspray
    var system2 = 11;//watering time for sand with sprinkler
    var system3 = 17;//watering time for sand wih minisprinker
    var system4 = 50; //watering time for sand with dripper

    var largeplants = * 1.5; //multiply by 1.5 if checkbox is selected

    var type1 //watering time for sand with all systems
    var type2 = * 2; //watering time for loam with jetspray/sprinkler/minisprinker/dripper
    var type3 = * 3.5;//watering time for clay with jetspray/sprinkler/minisprinker/dripper

    // Get the number of the selected answer (1, 2, 3 or 4)
    for (var i = 1; i <= 4; i++) {
    radioButton = document.getElementById("system" + i);
    if (radioButton.checked == true) {
    selectedAnswer = i;

    // Get the number of the selected answer (1, 2, or 3)
    for (var i = 1; i <= 3; i++) {
    radioButton = document.getElementById("type" + i);
    if (radioButton.checked == true) {
    selectedAnswer = i;




    <h1>Home Garden Watering Guide</h1>
    <p>Complete the form below to calculate the recommended watering time for your home garden.<br>
    <p>Watering System</p>
    <input type="radio" id="system1" name="system" value="JetSpray">
    <label for="jet">Jet Spray</label><br>
    <input type="radio" id="system2" name="system" value="Sprinkler">
    <label for="sprink">Sprinkler</label><br>
    <input type="radio" id="system3" name="system" value="MiniSprinkler">
    <label for="mini">Mini Sprinkler</label>
    <input type="radio" id="system4" name="system" value="Dripper">
    <label for="drip">Dripper</label>
    <p>Click Here if your plants are large
    <input type="checkbox" id="largeplants" name="plants"
    value="largeplants" onClick=" * 1.5 ">

    <p>Soil Type</p>
    <input type="radio" id="type1" name="soil" value="Sand">
    <label for="sand">Sand</label><br>
    <input type="radio" id="type2" name="soil" value="Loam">
    <label for="loam">Loam</label><br>
    <input type="radio" id="type3" name="soil" value="Clay">
    <label for="clay">Clay</label></form>
    <input type="submit" value="Calculate" id="calculateTime"
    onClick="calculateTime" alert("The recommended watering time is "" minutes"> <input type="reset" value="Reset">

    I know I haven't got through much so any and all help and hits to achieving this will be greatly appreciated.
    Also please clarify if I do need to use a loop in this instance

    Thanks heaps

  2. #2
    Join Date
    Jun 2004
    Portsmouth UK

    God loves you and will never love you less.

    If my post has been useful please donate to http://www.operationsmile.org.uk/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center