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 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    57
    Thanks
    8
    Thanked 0 Times in 0 Posts

    calculate and show total on another page

    I have a small price quote calculator/contact information form. I want the customer to fill out the whole form submit and get his estimated price based on selections in the form. I am using asp, and I have a javascript for the quote calculations. My question is how would I take this js and execute it when the user hits submit, and then displaying that quote price on the next page. Here is the javascript that I'm working with:

    Code:
     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;
    
     
    
     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;
     
    
    function getPracticeField()
    {
        var docPracticeField=0;
    
        var theForm = document.forms["quoteform"];
    
         var selectedPracticeField = theForm.elements["practice"];
         
        
        docPracticeField = practice_field[selectedPracticeField.value];
    
    
        return docPracticeField;
    }	 
    	 
    
    
    function getSelectedSociety()
    {
        var docSelectedSociety=0;
    
        var theForm = document.forms["quoteform"];
    
         var selectedSociety = theForm.elements["society"];
         
    
        docSelectedSociety = society_member[selectedSociety.value];
    
    
        return docSelectedSociety;
    }
    
    
    function bareDefensePrice()
    {
        var defensePrice=0;
    
        var theForm = document.forms["quoteform"];
    
        var includeDefense = theForm.elements["baredefense"];
    
      
        if(includeDefense.checked==true)
        {
            defensePrice=0;
        }
    
        return defensePrice;
    }
    
    
    
    function insuranceDefensePrice()
    {
    
        var insuranceDefense=0;
    
        var theForm = document.forms["quoteform"];
    
        var includeMoreDefense = theForm.elements["insureddefense"];
    
        if(includeMoreDefense.checked==true){
            insuranceDefense=0;
        }
     
        return insuranceDefense;
    }
    
    
            
    function calculateTotal()
    {
    
        var defensePrice = getPracticeField() + null - (getPracticeField() * getSelectedSociety()) + bareDefensePrice() + insuranceDefensePrice();
        
    
        var divobj = document.getElementById('totalPrice');
        divobj.style.display='block';
        divobj.innerHTML = "Your Pre-Paid Legal Defense Fee Will Be Around $"+defensePrice;
    
    }
    
    
    
    function hideTotal()
    {
        var divobj = document.getElementById('totalPrice');
        divobj.style.display='none';
    }
    here is the html
    Code:
    <body onload='hideTotal()'>
        <div id="wrap">
            <form action="" id="quoteform" onsubmit="">
            <div>
            
                <div class="cont_order">
                    <fieldset> 
                    <legend>How Much Will My Pre-Paid Legal Defense Cost?</legend>
                    <label >Choose Your Practice Field</label>
                    
                    <select id="practice" name='practice' onchange="calculateTotal()">
                    <option value="None">Select Field</option>
                    <option value="Allergy and Immunology">Allergy and Immunology</option>
                    <option value="Endocrinology">Endocrinology</option>
                    <option value="Pathology">Pathology</option>
                    <option value="Dermatology">Dermatology</option>
                    <option value="Geriatrics">Geriatrics</option>
                    <option value="Physical Rehabilitation">Physical Rehabilitation</option>
                    <option value="Family Practice">Family Practice</option>
                    <option value="General Practice">General Practice</option>
                    <option value="Internal Medicine">Internal Medicine</option>
                    <option value="Oncology">Oncology</option>
                    <option value="Oral Surgery">Oral Surgery</option>
                    <option value="Radiology">Radiology</option>
                    <option value="Gastroenterology">Gastroenterology</option>
                    <option value="Infectious Disease">Infectious Disease</option>
                    <option value="Nephrology">Nephrology</option>
                    <option value="Ophthalmology">Ophthalmology</option>
                    <option value="Pediatrics">Pediatrics</option>
                    <option value="Urology">Urology</option>
                    <option value="Anesthesiology">Anesthesiology</option>
                    <option value="Cosmetic Surgery">Cosmetic Surgery</option>
                    <option value="General Surgery">General Surgery</option>
                    <option value="Neurology">Neurology</option>
                    <option value="Otolaryngology">Otolaryngology</option>
                    <option value="Plastic Surgery">Plastic Surgery</option>
                    <option value="Vascular Surgery">Vascular Surgery</option>
                    <option value="Cardiology">Cardiology</option>
                    <option value="Emergency Medicine">Emergency Medicine</option>
                    <option value="Gynecology">Gynecology</option>
                    <option value="Orthopedic Surgery">Orthopedic Surgery</option>
                    <option value="Pain Management">Pain Management</option>
                    <option value="Pulmonary Surgery">Pulmonary Surgery</option>
                    <option value="Neurological Surgery">Neurological Surgery</option>
                    <option value="Obstetrics">Obstetrics</option>
                   </select>
                   
                    <br/>
                    <p>
                    <label >Are You Affiliated With Any of the Following Medical Societies</label>
             		<select id="society" name='society' onchange="calculateTotal()">
                    <option value="None">Select Society</option>
                    <option value="None">No, I am not</option>
                    <option value="BCMA">Broward County Medical Association</option>
                    <option value="DCMA">Dade County Medical Association</option>
                    <option value="FOGS">Florida Obstetrics & Gynecology Society</option>
                    <option value="FNS">Florida Neurological Society</option>
                    <option value="PBCMS">Palm Beach County Medical Society</option>
                    <option value="FSPS">Florida Society of Plastic Surgeons</option>
                    </select>
                    </p>
                    <br/>
                    
                    <label >What Type of Defense Are You Interested In?</label>
              		<br  />
                    <label for='baredefense' class="inlinelabel">Bare Defense</label>
                    <input type="checkbox" id="baredefense" name='baredefense' onclick="calculateTotal()" />
        
                    <br  />
                    <label class="inlinelabel" for='insureddefense'>Insured Defense</label>
                    <input type="checkbox" id="insureddefense" name="insureddefense" onclick="calculateTotal()" />
                    </p>
                    
                    <div id="totalPrice"></div>
                    
                    </fieldset>
                    
                </div>
                <div class="cont_details">
                	<fieldset>
                    <legend>Contact Details</legend>
                    <label for='name'>Name</label>
                    <input type="text" id="name" name='name' />
                    <br/>
                    <label for='address'>Address</label>
                    <input type="text" id="address" name='address' />
                    <br/>
                    <label for='phonenumber'>Phone Number</label>
                    <input type="text"  id="phonenumber" name='phonenumber'/>
                    <br/>
                    </fieldset>
                </div>
                <input type='submit' id='submit' value='Calculate Rate' onclick="calculateTotal()" />
            </div>  
           </form>
    	</div><!--End of wrap-->

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    I do not see a page assigned to the action attribute in the form tag does this mean that you have the form posting back onto the same page? if not what page is it posting to? Is the page the form goes to the page that you want to display the value on? if yes why bother with client side javascript at all when you can do it all server side?

    If doing a postback then there is a number of ways to do it
    1. use a cookie -- problem possibility of users disabling cookies
    2. use a session variable -- can have same problem as above though
    3. use an application variable -- no cookie issue but does have other issues
    4. allow javascript to move the user to the next page and pass in the querystring
    5. do the calculation server side before you move to the next page and send the value with it


  •  

    Posting Permissions

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