Treasad Posted February 15, 2010 Report Share Posted February 15, 2010 HEALTH INSURANCE QUESTIONNAIRE First Name: Last Name: Age: Address Line 1: Address Line 2: City: County: Post Code: History of Hereditary Disease: Heart Asthma Arthritis Exercise: Diet: Alcohol: Smoking: General Health: FrequentlyLow FatLightNon SmokerLight AverageAverageMediumLightAverage SeldomHigh FatHeavyHeavyPoor Quote Link to comment Share on other sites More sharing options...
administrator Posted February 16, 2010 Report Share Posted February 16, 2010 All you need to do is: 1. assign the text you want displayed to a variable - this will be spit out by a function that does the final calculations. 2. once you have that variable, use simple DOM scriptiing to target a div and then insert that value with the innerHTML property. Stefan Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 16, 2010 Report Share Posted February 16, 2010 Basically, you just need to add an if statement near the bottom of the Something like this: function validateFirstname() { if (document.insurance.firstname.value.length > 20) { alert ("First name must not be more than 20 characters") ; insurance.firstname.focus(); return (false); } } function validateLastname() { if (document.insurance.lastname.value.length > 30) { alert ("Last name must not be more than 30 characters") ; insurance.lastname.focus(); return (false); } } function txtAge_onblur() { var txtAge = document.insurance.txtAge; if (isNaN(txtAge.value) == true) { alert("Please enter a valid age"); txtAge.focus(); txtAge.select(); } if (document.insurance.txtAge.value.length > 3) { alert ("Age must not be more than 3 numbers"); insurance.txtAge.focus(); return (false); } } function addressone() { if (document.insurance.add1.value.length > 30) { alert ("Address Line 1 must not be more than 30 characters") ; insurance.add1.focus(); return (false); } } function addresstwo() { if (document.insurance.add2.value.length > 30) { alert ("Address Line 2 must not be more than 30 characters") ; insurance.add2.focus(); return (false); } } function citychar() { if (document.insurance.city.value.length > 20) { alert ("City must not be more than 20 characters") ; insurance.city.focus(); return (false); } } function countychar() { if (document.insurance.county.value.length > 20) { alert ("County must not be more than 20 characters") ; insurance.county.focus(); return (false); } } function postcodechar() { if (document.insurance.postcode.value.length > 10) { alert ("Postcode must not be more than 10 characters") ; insurance.postcode.focus(); return (false); } } var healthpoints = new Array(); healthpoints[100] = 10; healthpoints[101] = 10; healthpoints[102] = 10; healthpoints[200] = 0; healthpoints[201] = 5; healthpoints[202] = 10; healthpoints[300] = 0; healthpoints[301] = 5; healthpoints[302] = 10; healthpoints[400] = 0; healthpoints[401] = 5; healthpoints[402] = 10; healthpoints[500] = 0; healthpoints[501] = 5; healthpoints[502] = 10; healthpoints[600] = 0; healthpoints[601] = 5; healthpoints[602] = 10; function updateHealthDetails() { var total = 0; var healthDetails = " "; var formElement; formElement = document.insurance.heart if (formElement.checked == true) { healthDetails = healthDetails + "Heart : Points = " + healthpoints[formElement.value] + "\n"; total = total + parseFloat(healthpoints[formElement.value]); } formElement = document.insurance.asthma if (formElement.checked == true) { healthDetails = healthDetails + " Asthma : Points = " + healthpoints[formElement.value] + "\n"; total = total + parseFloat(healthpoints[formElement.value]); } formElement = document.insurance.arthritis if (formElement.checked == true) { healthDetails = healthDetails + " Arthritis : Points = " + healthpoints[formElement.value] + "\n"; total = total + parseFloat(healthpoints[formElement.value]); } formElement = document.insurance.exercise if (formElement[0].checked == true) { healthDetails = healthDetails + " I exercise frequently : Points = " + healthpoints[formElement[0].value] + "\n"; total = total + parseFloat(healthpoints[formElement[0].value]); } else if (formElement[1].checked == true) { healthDetails = healthDetails + " I exercise an average amount of time : Points = " + healthpoints[formElement[1].value] + "\n"; total = total + parseFloat(healthpoints[formElement[1].value]); } else { healthDetails = healthDetails + " I seldom exercise : Points = " + healthpoints[formElement[2].value] + "\n"; total = total + parseFloat(healthpoints[formElement[2].value]); } formElement = document.insurance.diet if (formElement[0].checked == true) { healthDetails = healthDetails + " My diet is low fat : Points = " + healthpoints[formElement[0].value] + "\n"; total = total + parseFloat(healthpoints[formElement[0].value]); } else if (formElement[1].checked == true) { healthDetails = healthDetails + " I eat an average amount of fat in my diet : Points = " + healthpoints[formElement[1].value] + "\n"; total = total + parseFloat(healthpoints[formElement[1].value]); } else { healthDetails = healthDetails + " My diet is high fat : Points = " + healthpoints[formElement[2].value] + "\n"; total = total + parseFloat(healthpoints[formElement[2].value]); } formElement = document.insurance.alcohol if (formElement[0].checked == true) { healthDetails = healthDetails + " I do not drink much alcohol : Points = " + healthpoints[formElement[0].value] + "\n"; total = total + parseFloat(healthpoints[formElement[0].value]); } else if (formElement[1].checked == true) { healthDetails = healthDetails + " I drink an average amount of alcohol : Points = " + healthpoints[formElement[1].value] + "\n"; total = total + parseFloat(healthpoints[formElement[1].value]); } else { healthDetails = healthDetails + " I drink a lot of alcohol : Points = " + healthpoints[formElement[2].value] + "\n"; total = total + parseFloat(healthpoints[formElement[2].value]); } formElement = document.insurance.smoking if (formElement[0].checked == true) { healthDetails = healthDetails + " I do not smoke : Points = " + healthpoints[formElement[0].value] + "\n"; total = total + parseFloat(healthpoints[formElement[0].value]); } else if (formElement[1].checked == true) { healthDetails = healthDetails + " I am a light smoker : Points = " + healthpoints[formElement[1].value] + "\n"; total = total + parseFloat(healthpoints[formElement[1].value]); } else { healthDetails = healthDetails + " I am a heavy smoker : Points = " + healthpoints[formElement[2].value] + "\n"; total = total + parseFloat(healthpoints[formElement[2].value]); } formElement = document.insurance.general if (formElement[0].checked == true) { healthDetails = healthDetails + " My health is good : Points = " + healthpoints[formElement[0].value]; total = total + parseFloat(healthpoints[formElement[0].value]); } else if (formElement[1].checked == true) { healthDetails = healthDetails + " My health is average : Points = " + healthpoints[formElement[1].value]; total = total + parseFloat(healthpoints[formElement[1].value]); } else { healthDetails = healthDetails + " My health is poor : Points = " + healthpoints[formElement[2].value]; total = total + parseFloat(healthpoints[formElement[2].value]); } healthDetails = healthDetails + "\n\n Total Points: " + total; // edits if (total { healthDetails = healthDetails + "\n\n You are low risk."; } else if (total { healthDetails = healthDetails + "\n\n You are medium risk."; } else { healthDetails = healthDetails + "\n\n You are high risk."; } // end edits document.insurance.txtOrder.value = healthDetails; } Quote Link to comment Share on other sites More sharing options...
Treasad Posted February 16, 2010 Author Report Share Posted February 16, 2010 Thank you falkencreative. It works perfectly, really appreciate your help Quote Link to comment Share on other sites More sharing options...
Treasad Posted February 16, 2010 Author Report Share Posted February 16, 2010 All you need to do is: 1. assign the text you want displayed to a variable - this will be spit out by a function that does the final calculations. 2. once you have that variable, use simple DOM scriptiing to target a div and then insert that value with the innerHTML property. Stefan Thanks Stefan, I appreciate your help. I have it up and running. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.