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 6 of 6
  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 it, and get his/her 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 display 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
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I am afraid that is not valid Javascript syntax.

    The best way to do this is to make the value of each option the name of the subject and the cost conjoined with a ~, then split these two values out:-

    Code:
    <form>
    <select id="practice" name='practice' onchange="calculateTotal()">
    <option value="None~0">Select Field</option>
    <option value="Allergy and Immunology~4400">Allergy and Immunology</option>
                    <option value="Endocrinology~4400">Endocrinology</option>
                    <option value="Pathology~4400">Pathology</option>
                    <option value="Dermatology~4400">Dermatology</option>
                    <option value="Obstetrics~9900">Obstetrics</option>
    
    </select>
    </form>
    
    <script type = "text/javascript">
    
    function calculateTotal() {
    var val = document.forms[0].practice.value;
    var valsplit = val.split("~");
    var pfield = valsplit[0];
    var cost = valsplit[1];
    if (cost >0) {
    alert ("You selected " + pfield + " which costs $" + cost);
    }
    }
    </script>
    Same for the society memberships. If there is a discount suggest you make the values .9 so the cost can be multipled by that simple value. Obviously the default value = 1.

    Code:
    <option value="BCMA~.9">Broward County Medical Association</option>
    Be aware that var theForm = document.forms["quoteform"]; will only work in IE. You must assign the name "quoteform" to your form. Or use (as I have done) document.forms[0] - assuming that there is only the one form on the page.

    If you wish to pass the final value to another page, you need to use a query string.



    He lied like an eye witness. - Russian proverb
    Last edited by Philip M; 03-05-2012 at 05:52 PM. Reason: typo

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    57
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks for the reply, now as far as using the query string to pass on the value. Since that total price/value is calculated in a div. How would I pass that on? Would it be something like:

    Dim total As String
    total = Request.QueryString("totalPrice")

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Suggest you Google for "Javascript query string" where you will find many good tutorials. Example:-

    http://javascript.about.com/library/blqs.htm

    But I would get my main page working properly before you take the next step. There are signs that you are mixing up computer languages.
    Last edited by Philip M; 03-05-2012 at 06:39 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Sep 2011
    Posts
    57
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Alright thanks for the link.

    Now if I want the person to hit submit and then be shown the total on another page, I would have to include a 'form action' and put the javascript that does the totals on that page as well as asp code receiving the query strings? Im new to asp, so I have been having trouble figuring this out, and I need to have it completed by today or tomorrow . Need help guys.
    Last edited by eiger23; 03-05-2012 at 08:36 PM.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    One more time - I would get my main page working properly before you take the next step. There are signs that you are mixing up computer languages.

    Might I respectfully suggest that, just as I would pay a professional oncologist (whatever that is ) if i wanted my oncs attended to, that you pay a professional programmer to construct your website? Or is it a case of "Jack of all trades ....."?

    If you are using asp why do you not pass the value to the next page using that?
    Last edited by Philip M; 03-06-2012 at 08:17 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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