please can anyone tell me why this script doesnt seem to work.thankz

<script>
function calculate (){
var age = document.getElementById('age');
var amt = document.getElementById('amount');
var plan = document.getElementById('plan');
var ben1 = document.getElementById('benefit1');
var ben2 = document.getElementById('benefit2');
var yrs = document.getElementById('length');

var ap = (amt.value/yrs.value)+Math.pow((100*Math.sqrt(age.value/(55*yrs.value))),2);
document.write('annual premium'+ap);
}

function checkplan(){
var plan = document.getElementById('plan');
var age = document.getElementById('age');
var but = document.getElementById('calculate');

if (plan.value == 5){
yrs.disabled = false;
}
else if (plan.value == 4){
yrs.value = 25;
if((age.value + 25)>60){
alert("The maximum age allowed for this policy at maturity is 60.Please choose another Policy");
calculate.disabled = true;
}
}
else if (plan.value == 3){
yrs.value = 20;
if((age.value + 20)>60){
alert("The maximum age allowed for this policy at maturity is 60.Please choose another Policy");
calculate.disabled = true;
}
}
else if (plan.value == 2){
yrs.value = 15;
if((age.value + 15)>60){
alert("The maximum age allowed for this policy at maturity is 60.Please choose another Policy");
calculate.disabled = true;
}
}
else if (plan.value == 1){
yrs.value = 10;
if((age.value + 10)>60){
alert("The maximum age allowed for this policy at maturity is 60.Please choose another Policy");
calculate.disabled = true;
}
}
}

function checkyear(){
var yrs = document.getElementById('length');
var age = document.getElementById('age');

if((yrs.value+age.value) >60) {
alert("The maximum age allowed for this policy at maturity is 60.Please choose another Policy");
calculate.disabled = true;
}

}
</script>

</head>

<body>

       <form action="" method="post" name="secure"><table width="514" height="158" border="0" cellpadding="0" cellspacing="0">
  <tr align="center">
    <td width="276" height="30"><span id="sprytextfield1">
      <label>Name:
        <input type="text" name="name" id="name" accesskey="n" tabindex="1" />
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
    <td width="224"><span id="sprytextfield2">
      <label>Age:
        <input type="text" name="age" id="age" />
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
  </tr>
  <tr align="center">
    <td height="29"><span id="sprytextfield3">
      <label>Cover Amount:
        <input type="text" name="amount" id="amount" />
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
    <td>&nbsp;</td>
  </tr>
  <tr align="center">
    <td height="34"><label>Plan:
      <select name="plan" id="plan" onblur="checkplan();">
        <option value="0">none</option>
        <option value="1">money back 10</option>
        <option value="2">money back 15</option>
        <option value="3">money back 20</option>
        <option value="4">money back 25</option>
        <option value="5">whole life</option>
      </select>
    </label></td>
    <td><label>
      <input type="checkbox" name="benefit1" id="benefit1" />
      Term Rider </label><label><input name="benefit2" type="checkbox" id="benefit2" />Critical Illness</label></td>
  </tr>
  <tr align="center">
    <td height="37"><span id="sprytextfield4">
      <label>Length of Cover (Yrs):
        <input name="length" type="text" disabled="true" id="length" onblur="checkyear();"/>
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
    <td><label>
      <input type="button" name="calculate" id="calculate" value="Calculate" onclick="calculate();"/>
    </label></td>
  </tr>
  <tr align="center">
    <td><span id="sprytextfield5">
      <label>Monthly Premium:
        <input name="mpremium" type="text" disabled="disabled" id="mpremium" />
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
    <td><span id="sprytextfield6">
      <label>Annual Premium
        <input name="apremium" type="text" disabled="disabled" id="apremium" />
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
  </tr>
    <tr align="center">
    <td><span id="sprytextfield7">
      <label>Bonus at Maturity:
        <input name="bonus" type="text" disabled="disabled" id="bonus" />
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
    <td></td>
  </tr>
</table>
</form>

</body>

Do NOT give an element a name and/or id that is the same as a javascript function. This would result in a name collision. Rename your function to Calculate (upper case "C") and update the onclick attribute on line 111.

Also, in checkplan() it looks like this: var but = document.getElementById('calculate'); should be: var calculate = document.getElementById('calculate'); AND you are also missing the following in that function: var yrs = document.getElementById('length');

thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.