#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Beginner - Help!


    Hi all,
    I am a beginner with javascript and programming: i have had a go at creating a piece of software with a form and 3 on click functions to process a quote: but it doesnt work!
    Can anyone take a look and see if the logic is ok or whether i need to scrap it and start again?
    The form works but will not call the test_click, clear_click or submit_click functions..
    Underneath is the form
    Cheers


    <form action="" name="clientquoteform">

    Business Name: <input type="text" name="businessname"><br>
    Contact Name: <input type="text" name="contactname"><br>
    Contact Number: <input type="text" name="contactnumber"><br>
    Billing Address: <input type="text" name="billingaddress"><br>
    Address Where Service is Required: <input type="text" name="serviceaddress"><br>
    <br>



    Choose From The Following: <br>
    <input type="radio" name="regularoronce" value="regular">Regular Service
    <input type="radio" name="regularoronce" value="once">Once-Only Service <br>
    <br>



    If Regular; How often do you require the service? <br>
    <input type="radio" name="frequency" value="everymonth"> Every Month (12 per Year) <br>
    <input type="radio" name="frequency" value="sixmonths"> Every Six Months (2 per Year) <br>
    <input type="radio" name="frequency" value="annually"> Annually (1 per Year) <br>
    <br>

    If Regular; What is the length of the contract? <br>
    <input type="radio" name="contractlength" value="oneyear"> 1 Year <br>
    <input type="radio" name="contractlength" value="twoyears"> 2 Years <br>
    <input type="radio" name="contractlength" value="threeyears"> 3 Years <br>
    <br>




    How many people are to be served?
    <input type="text" name="numberpeople"><br>
    <br>


    Is the buffet meal: <br>
    <input type="radio" name="numbercourses" value="onecourse"> 1 Course <br>
    <input type="radio" name="numbercourses" value="twocourses"> 2 Courses <br>
    <br>


    Is the buffet meal to include tea or coffee? <br>
    <input type="radio" name="teacoffee" value="yes"> Yes <br>
    <input type="radio" name="teacoffee" value="no"> No <br>
    <br>


    Is the service to be prepared: <br>
    <input type="radio" name="onsiteoffsite" value="onsite"> On-Site <br>
    <input type="radio" name="onsiteoffsite" value="offsite"> Off-Site and Delivered <br>
    <br>


    <br>
    <input type="button" value="Check Details" onclick="test_click();">
    <br>

    <input type="reset" value="Reset" onclick="clear_click();">


    <input type="submit" value="Submit" onclick="submit_click();">
    <br>
    <br>
    <textarea name="output" rows="15" cols="40">
    </textarea>
  2. #2
  3. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,009
    Rep Power
    2791
    Welcome to DevShed, langmp.

    Can you post everything please, including the Javascript.
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0
    <head>
    <h1> BuffetQuote Application </h1>
    </head>

    <body>
    <script language = "javascript">


    //declaring variables

    var myForm = document.form1;

    var businessName = myForm.businessname.value;
    var contactName = myForm.contactname.value;
    var contactNumber = myForm.contactnumber.value;
    var billingAddress = myForm.billingaddress.value;
    var serviceAddress = myForm.serviceaddress.value;

    var regular = myForm.regularoronce.regular;
    var once = myForm.regularoronce.once;

    var everyMonth = myForm.frequency.everymonth;
    var sixMonths = myForm.frequency.sixmonths;
    var annually = myForm.frequency.annually;

    var oneYear = myForm.contractlength.oneyear;
    var twoYears = myForm.contractlength.twoyears;
    var threeYears = myForm.contractlength.threeyears;

    var numberPeople = myForm.numberpeople.value;

    var oneCourse = myForm.numbercourses.onecourse;
    var twoCourses = myForm.numbercourses.twocourses;

    var teaCoffee = myForm.teacoffee.yes;
    var noTeaCoffee = myForm.teacoffee.no;

    var onSite = myForm.onsiteoffsite.onsite;
    var offSite = myForm.onsiteoffsite.offsite;

    var output = myForm.output.value

    var totalCost;
    var Gst;
    var totalCostGst;



    //function 1: onclick from 'check details' button. validates form entries.

    function test_click()
    {

    //validate that number of people is a number

    if(isNaN(numberPeople) == true)
    {
    alert("Please enter a valid number");
    }

    //validate that regular or once radio is completed

    if (regular== null && once == null)
    {
    alert("Please complete all sections");
    return;
    }

    //validate that frequency radio is completed

    if (everyMonth==null && sixMonths==null && annually==null)
    {
    alert("Please complete all sections");
    return;
    }

    //validate that contract length radio is completed

    if (oneYear==null && twoYears==null && threeYears==null)
    {
    alert("Please complete all sections");
    return;
    }

    //validate that number of courses radio is completed

    if (oneCourse== null && twoCourses == null)
    {
    alert("Please complete all sections");
    return;
    }

    //validate that tea or coffee radio is completed

    if (teaCoffee== null && noTeaCoffee == null)
    {
    alert("Please complete all sections");
    return;
    }

    //validate that onsite or offsite radio is completed

    if (onSite== null && offSite== null)
    {
    alert("Please complete all sections");
    return;
    }

    //validate that all entry boxes are completed

    if (businessName==""||contactName==""||billingAddress==""||serviceAddress==""||contactNumber==""||numbe rPeople=="")
    {
    alert("Please complete all sections");

    }

    //validate that the form is successfully completed, requests user to submit

    else
    {
    alert("Details are valid: Please click submit");

    }


    }


    //function 2: reset: clears form and starts from blank

    function clear_click()
    {
    document.getElementById("clientquoteform").reset();
    alert("Form Reset")
    }


    //function 3: submit: calculates the quote and outputs the variables

    function submit_click()
    {

    //calculate base cost for less than 30people, 1 course

    if (numberPeople <= 30 && oneCourse)
    {
    totalCost = 10 * numberPeople;
    }

    //calculate base cost for less than 30 people, 2 courses

    if (numberPeople <= 30 && twoCourses)
    {
    totalCost = 15 * numberPeople;
    }

    //calculate base cost for over 30 people, 1 course

    if (numberPeople > 30 && oneCourse)
    {
    totalCost = 8 * numberPeople;
    }

    //calculate base cost for between 30 and 60 people, 2 courses

    if (numberPeople > 30 && numberPeople <=60 && twoCourses)
    {
    totalCost = 12 * numberPeople;
    }

    //calculate base cost for over 60 people, 2 courses

    if (numberPeople > 60 && twoCourses)
    {
    totalCost = 11 * numberPeople;
    }

    //calculate additional cost of tea or coffee, and add text to variable for output

    if (teaCoffee)
    {
    totalCost = totalCost + (2 * numberPeople);
    teaCoffee = "Tea or Coffee Included";
    }

    //calculate additional cost of delivery, and add text to variable for output

    if(offSite)
    {
    totalCost = totalCost + (totalCost * 0.03);
    offSite = "Prepared Off-Site - Delivery Included";
    }

    //calculate discount of every month service, and add text to variable for output

    if(everyMonth)
    {
    totalCost = totalCost - (totalCost * 0.05);
    everyMonth = "Monthly Service Selected";
    {

    //calculate the discount of six monthly service, and add text to variable for output

    if(sixMonths)
    {
    totalCost = totalCost - (totalCost * 0.04);
    sixmonths = "Six Monthly Service Selected";
    }

    //calculate the discount of annual service, and add text to variable for output

    if(annually)
    {
    totalCost = totalCost - (totalCost * 0.03);
    annually = "Annual Service Selected";
    }

    //calculate the discount of a one year contract, and add text to variable for output

    if(oneYear)
    {
    totalCost = totalCost - (totalCost * 0.02);
    oneYear = "One Year Contract Selected";
    }

    //calculate the discount of a two year contract, and add text to variable for output

    if(twoYears)
    {
    totalCost = totalCost - (totalCost * 0.04);
    twoYears = "Two Year Contract Selected";
    }

    //calculate the discount of a three year contract, and add text to variable for output

    if(threeYears)
    {
    totalCost = totalCost - (totalCost * 0.06);
    threeYears = "Three Year Contract Selected";

    }


    //add text to other possible radio variables for output

    if(regular)
    {
    regular = "Regular Service Selected";
    }
    if(once)
    {
    once = "Once-Only Service Selected";
    }
    if(oneCourse)
    {
    oneCourse = "One-Course Meal Selected";
    }
    if(twoCourses)
    {
    twoCourses = "Two-Course Meal Selected";
    }
    if(noTeaCoffee)
    {
    noTeaCoffee = "No Tea or Coffee Selected";
    }

    //convert total cost to 2 decimal places

    totalCost = totalCost.toFixed(2);
    totalCost = "Pre-GST Total Cost = $" + totalCost;


    //calculate GST to 2 decimal places

    Gst = totalCost * 0.1
    Gst = Gst.toFixed(2)
    Gst = "GST Added = $" + Gst;

    //calculate total cost with GST included

    totalCostGst = totalCost + Gst
    totalCostGst = "Total Cost including GST = $" + totalCostGst;

    //output all required variables in text field

    output = (businessName + "<br>" + contactName + "<br>" + contactNumber +
    "<br>" + billingAddress + "<br>" + serviceAddress + "<br>" + regular +
    "<br>" + once + "<br>" + everyMonth + "<br>" + sixMonths + "<br>" + annually +
    "<br>" + oneYear + "<br>" + twoYears + "<br>" + threeYears + "<br>" + numberPeople +
    "<br>" + oneCourse + "<br>" + twoCourses + "<br>" + teaCoffee + "<br>" + noTeaCoffee +
    "<br>" + onSite + "<br>" + offSite + "<br>" + totalCost + "<br>" + Gst + "<br>" + totalCostGst )

    }

    </script>


    <form name="clientquoteform" action ="">

    Business Name: <input type="text" name="businessname"><br>
    Contact Name: <input type="text" name="contactname"><br>
    Contact Number: <input type="text" name="contactnumber"><br>
    Billing Address: <input type="text" name="billingaddress"><br>
    Address Where Service is Required: <input type="text" name="serviceaddress"><br>
    <br>

    Choose From The Following: <br>
    <input type="radio" name="regularoronce" value="regular">Regular Service
    <input type="radio" name="regularoronce" value="once">Once-Only Service <br>
    <br>

    If Regular; How often do you require the service? <br>
    <input type="radio" name="frequency" value="everymonth"> Every Month (12 per Year) <br>
    <input type="radio" name="frequency" value="sixmonths"> Every Six Months (2 per Year) <br>
    <input type="radio" name="frequency" value="annually"> Annually (1 per Year) <br>
    <br>

    If Regular; What is the length of the contract? <br>
    <input type="radio" name="contractlength" value="oneyear"> 1 Year <br>
    <input type="radio" name="contractlength" value="twoyears"> 2 Years <br>
    <input type="radio" name="contractlength" value="threeyears"> 3 Years <br>
    <br>

    How many people are to be served?
    <input type="text" name="numberpeople"><br>
    <br>

    Is the buffet meal: <br>
    <input type="radio" name="numbercourses" value="onecourse"> 1 Course <br>
    <input type="radio" name="numbercourses" value="twocourses"> 2 Courses <br>
    <br>

    Is the buffet meal to include tea or coffee? <br>
    <input type="radio" name="teacoffee" value="yes"> Yes <br>
    <input type="radio" name="teacoffee" value="no"> No <br>
    <br>

    Is the service to be prepared: <br>
    <input type="radio" name="onsiteoffsite" value="onsite"> On-Site <br>
    <input type="radio" name="onsiteoffsite" value="offsite"> Off-Site and Delivered <br>
    <br>

    <br>
    <input type="button" value="Check Details" onclick="test_click()">
    <br>

    <input type="reset" value="Reset" onclick="clear_click()">

    <input type="submit" onclick="submit_click()" value="Submit"">
    <br>
    <br>
    <textarea name="output" rows="15" cols="40">
    </textarea>

    </form1>

    </body>

IMN logo majestic logo threadwatch logo seochat tools logo