Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    57
    Thanks
    8
    Thanked 0 Times in 0 Posts

    display quote results on another page when user hits submit

    I have a small form that I'm working on for a client. They want a form that their potential leads can fill out and then hit 'calculate rate'.

    Once this is done, the results should display on another page with a short summary of what their quote will be as well as some of the other information they filled out. It should also send an email to my client displaying the information that their lead just filled out. My only problem is I am not sure how to go about the calculation part. I know I would have to do an onSubmit, but how would I hide that calculation and then receive that number on another page. Here is the javascript for that form:

    Code:
    /*
    This source is shared under the terms of LGPL 3
    www.gnu.org/licenses/lgpl.html
    
    You are free to use the code in Commercial or non-commercial projects
    */
    
     //Set up an associative array
     //The keys represent the size of the cake
     //The values represent the cost of the cake i.e A 10" cake cost's $35
     var practice_field = new Array();
    practice_field["None"]=0;
    practice_field["Allergy and Immunology"]=4400;
    practice_field["Endocrinology"]=4400;
    practice_field["Pathology"]=4400;
    practice_field["Dermatology"]=4400;
    practice_field["Geriatrics"]=4400;
    practice_field["Physical Rehabilitation"]=4400;
    practice_field["Family Practice"]=6900;
    practice_field["General Practice"]=6900;
    practice_field["Internal Medicine"]=6900;
    practice_field["Oncology"]=6900;
    practice_field["Oral Surgery"]=6900;
    practice_field["Radiology"]=6900;
    practice_field["Gastroenterology"]=6900;
    practice_field["Infectious Disease"]=6900;
    practice_field["Nephrology"]=6900;
    practice_field["Ophthalmology"]=6900;
    practice_field["Pediatrics"]=6900;
    practice_field["Urology"]=6900;
    practice_field["Anesthesiology"]=9000;
    practice_field["Cosmetic Surgery"]=9000;
    practice_field["General Surgery"]=9000;
    practice_field["Neurology"]=9000;
    practice_field["Otolaryngology"]=9000;
    practice_field["Plastic Surgery"]=9000;
    practice_field["Vascular Surgery"]=9000;
    practice_field["Cardiology"]=9000;
    practice_field["Emergency Medicine"]=9000;
    practice_field["Gynecology"]=9000;
    practice_field["Orthopedic Surgery"]=9000;
    practice_field["Pain Management"]=9000;
    practice_field["Pulmonary Surgery"]=9000;
    practice_field["Neurological Surgery"]=9900;
    practice_field["Obstetrics"]=9900;
    
     
     //Set up an associative array 
     //The keys represent the filling type
     //The value represents the cost of the filling i.e. Lemon filling is $5,Dobash filling is $9
     //We use this this array when the user selects a filling from the form
     var society_member= new Array();
     society_member["None"]=null;
    society_member["BCMA"]=0.10;
    society_member["DCMA"]=0.10;
    society_member["FOGS"]=0.10;
    society_member["FNS"]=0.10;
    society_member["PBCMS"]=0.10;
    society_member["FSPS"]=0.10;
     
    //This function finds the filling price based on the 
    //drop down selection
    function getPracticeField()
    {
        var docPracticeField=0;
        //Get a reference to the form id="cakeform"
        var theForm = document.forms["cakeform"];
        //Get a reference to the select id="filling"
         var selectedPracticeField = theForm.elements["practice"];
         
        //set cakeFilling Price equal to value user chose
        //For example filling_prices["Lemon".value] would be equal to 5
        docPracticeField = practice_field[selectedPracticeField.value];
    
        //finally we return cakeFillingPrice
        return docPracticeField;
    }	 
    	 
    
    
    //This function finds the filling price based on the 
    //drop down selection
    function getSelectedSociety()
    {
        var docSelectedSociety=0;
        //Get a reference to the form id="cakeform"
        var theForm = document.forms["cakeform"];
        //Get a reference to the select id="filling"
         var selectedSociety = theForm.elements["society"];
         
        //set cakeFilling Price equal to value user chose
        //For example filling_prices["Lemon".value] would be equal to 5
        docSelectedSociety = society_member[selectedSociety.value];
    
        //finally we return cakeFillingPrice
        return docSelectedSociety;
    }
    
    //candlesPrice() finds the candles price based on a check box selection
    function candlesPrice()
    {
        var candlePrice=0;
        //Get a reference to the form id="cakeform"
        var theForm = document.forms["cakeform"];
        //Get a reference to the checkbox id="includecandles"
        var includeCandles = theForm.elements["includecandles"];
    
        //If they checked the box set candlePrice to 5
        if(includeCandles.checked==true)
        {
            candlePrice=0;
        }
        //finally we return the candlePrice
        return candlePrice;
    }
    
    function insciptionPrice()
    {
        //This local variable will be used to decide whether or not to charge for the inscription
        //If the user checked the box this value will be 20
        //otherwise it will remain at 0
        var inscriptionPrice=0;
        //Get a refernce to the form id="cakeform"
        var theForm = document.forms["cakeform"];
        //Get a reference to the checkbox id="includeinscription"
        var includeInscription = theForm.elements["includeinscription"];
        //If they checked the box set inscriptionPrice to 20
        if(includeInscription.checked==true){
            inscriptionPrice=0;
        }
        //finally we return the inscriptionPrice
        return inscriptionPrice;
    }
            
    function calculateTotal()
    {
        //Here we get the total price by calling our function
        //Each function returns a number so by calling them we add the values they return together
        var cakePrice = getPracticeField() + null - (getPracticeField() * getSelectedSociety()) + candlesPrice() + insciptionPrice();
        
        //display the result
        var divobj = document.getElementById('totalPrice');
        divobj.style.display='block';
        divobj.innerHTML = "Your Pre-Paid Legal Defense Fee Will Be Around $"+cakePrice;
    
    }
    
    function hideTotal()
    {
        var divobj = document.getElementById('totalPrice');
        divobj.style.display='none';
    }
    If you look at the bottom you can see where the Function that Calculates everything is. Right now it calculates onClick. I just want it to calculate after the user has filled out the form completely and display that calculation on another page along with the rest of the information they inputted.

  • #2
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    To produce any results on another page, and to send an email to the client you'll need more than javascript! You'll need to use a server side language such as PHP.

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    57
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Hey Dan,

    Thanks for the reply, I forgot to mention that I am using asp.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,185
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    So why not just do it all in ASP code and forget the JavaScript? Now your users don't have to have JavaScript enabled for your code to work.

    And don't you think you could have gone to the trouble to change some of the names in the JS code? I mean... cakefilling? candles? when you are talking about insurance?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by eiger23 View Post
    I have a small form that I'm working on for a client.
    Are you sure this is for a client and not a homework exercise of some sort?

    If you really do have a client, does your client know that you are using a forum to hopefully get someone to alter some third party code (which appears you haven't written) to suit your client's requirements. In essence, it appears you are trying to get someone else to write the code I assume your client is expecting you to write and you are charging your client for it.

    What you want to do is fairly basic and straight forward. Why you want to do this with javascript is beyond me. If it can be done server side, then that is where it should be done and this can certainly be done very easily server side.


  •  

    Posting Permissions

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