Link to home
Start Free TrialLog in
Avatar of garethtnash
garethtnashFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Javascript Calculation

Hello,

I have a or with a number of input options -

<form action="" method="post" name="form1" id="form1" onsubmit="return validateform1(this)">
<h3>Complete Survey Now</h3>
<ul>
    <li>
      <label>Retainer Value :</label>
      <input name="Locality" type="hidden" id="Locality" value="<%=(RSMemberLocality.Fields.Item("Locality").Value)%>" />        <input name="Retainerinput" type="hidden" id="Retainerinput" value="yes" />        
      <input name="RetainerValue" type="text" id="RetainerValue" maxlength="8" onBlur="this.value = formatField(this)" />
      </li>
    <li>
      <label>Fee Commission :</label>
      <input name="FeeCommission" type="text" id="FeeCommission" maxlength="8" onBlur="this.value = formatField(this)" />
      </li>
    <li>
      <label>Total :</label>
      <input name="TotalRetainer" type="text" id="TotalRetainer" maxlength="8" onBlur="this.value = formatField(this)" />
      </li>
    <li>
      <label>Date of Review </label>
      <input type="text" id="ReviewDate" name="ReviewDate" />

      </li>
    <li>
      <label>Comments</label>
      <div class="retainerholdertextarea"><textarea name="Comments" cols="36" rows="5" id="Comments"></textarea></div>
      <input type="image" class="submitbutton" src="png/submit.png">
      </li>
</ul>
</form>

Open in new window


I would like it if

TotalRetainer was a calculated value based on the input into either or both of -

RetainerValue
FeeCommission

So if only FeeCommision is entered the value in TotalRetainer  is the same as the value in FeeCommission, OR if both are entered the value is the Sum of both.

The calculation needs to happen on blur of either input.

And nost importantly, the input needsto be updateable, so if the sum of both is 10, but more parameters are involved and the actual total is 12, the user can over write the javascript calculated value...

Appreciate any help you can offer - Many thanks

Avatar of garethtnash
garethtnash
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Hi - slight update -

I've tried -

<script>
<!--
function calc(RetainerValue,FeeCommission,SUM) {
  var one = document.getElementById(RetainerValue).value;
  var two = document.getElementById(FeeCommission).value;
  document.getElementById(SUM).value = one + two;
}
//-->
</script>

AND

      <td><input name="Locality" type="hidden" id="Locality" value="<%=(RSMemberLocality.Fields.Item("Locality").Value)%>" />        <input name="Retainerinput" type="hidden" id="Retainerinput" value="yes" />        
      <input name="RetainerValue" type="text" id="RetainerValue" maxlength="8" onBlur="this.value = formatField(this);calc('one','two','TotalRetainer')" /></td>
      </tr>
    <tr class="altrow">
      <td class="labelcolumn">Fee Commission :</td>
      <td><input name="FeeCommission" type="text" id="FeeCommission" maxlength="8" onBlur="this.value = formatField(this);calc('one','two','TotalRetainer')" /></td>
      </tr>
    <tr>
      <td class="labelcolumn">Total :</td>
      <td><input name="TotalRetainer" type="text" id="TotalRetainer" maxlength="8" onBlur="this.value = formatField(this)" /></td>


But no joy -

Thanks
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi COBOLdinosaur,

Thanks for the post, but sadly no joy..

Thanks
SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Guys