Jump to content

Recommended Posts

Posted









HEALTH INSURANCE QUESTIONNAIRE



Health Insurance Logo image


Image to divide page





First Name:






Last Name:






Age:





Address Line 1:







Address Line 2:





City:





County:





Post Code:






Image to divide page



History of Hereditary Disease:
     

Heart
     Asthma
     Arthritis






Exercise:


Diet:


Alcohol:


Smoking:


General Health:





Frequently

Low Fat

Light

Non Smoker

Light


Average

Average

Medium

Light

Average


Seldom

High Fat

Heavy

Heavy

Poor







    









Posted

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

Posted

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

Posted
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. :)

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...