View Full Version : calculate and show total on another page

03-05-2012, 04:58 PM
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:

var practice_field = new Array();
practice_field["Allergy and Immunology"]=4400;
practice_field["Physical Rehabilitation"]=4400;
practice_field["Family Practice"]=6900;
practice_field["General Practice"]=6900;
practice_field["Internal Medicine"]=6900;
practice_field["Oral Surgery"]=6900;
practice_field["Infectious Disease"]=6900;
practice_field["Cosmetic Surgery"]=9000;
practice_field["General Surgery"]=9000;
practice_field["Plastic Surgery"]=9000;
practice_field["Vascular Surgery"]=9000;
practice_field["Emergency Medicine"]=9000;
practice_field["Orthopedic Surgery"]=9000;
practice_field["Pain Management"]=9000;
practice_field["Pulmonary Surgery"]=9000;
practice_field["Neurological Surgery"]=9900;

var society_member= new Array();

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"];


return defensePrice;

function insuranceDefensePrice()

var insuranceDefense=0;

var theForm = document.forms["quoteform"];

var includeMoreDefense = theForm.elements["insureddefense"];


return insuranceDefense;

function calculateTotal()

var defensePrice = getPracticeField() + null - (getPracticeField() * getSelectedSociety()) + bareDefensePrice() + insuranceDefensePrice();

var divobj = document.getElementById('totalPrice');
divobj.innerHTML = "Your Pre-Paid Legal Defense Fee Will Be Around $"+defensePrice;


function hideTotal()
var divobj = document.getElementById('totalPrice');

here is the html:

<body onload='hideTotal()'>
<div id="wrap">
<form action="" id="quoteform" onsubmit="">

<div class="cont_order">
<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>

<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>

<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()" />

<div id="totalPrice"></div>


<div class="cont_details">
<legend>Contact Details</legend>
<label for='name'>Name</label>
<input type="text" id="name" name='name' />
<label for='address'>Address</label>
<input type="text" id="address" name='address' />
<label for='phonenumber'>Phone Number</label>
<input type="text" id="phonenumber" name='phonenumber'/>
<input type='submit' id='submit' value='Calculate Rate' onclick="calculateTotal()" />
</div><!--End of wrap-->

Philip M
03-05-2012, 05:29 PM
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:-

<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>


<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);

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.

<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

03-05-2012, 06:11 PM
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")

Philip M
03-05-2012, 06:36 PM
Suggest you Google for "Javascript query string" where you will find many good tutorials. Example:-


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.

03-05-2012, 08:25 PM
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.

Philip M
03-06-2012, 08:12 AM
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 :D) 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?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum