PDA

View Full Version : Calculte TextBox example TextBox Calculations help



vega55
03-06-2014, 04:07 AM
demo.rsjoomla.com/calculation-form-example

TextBox Calculations
html code

<div class="componentheading">{global:formtitle}</div>
{error}
<table border="0">
<tr class="rsform-block rsform-block-field1">
<td>{field1:caption}</td>
<td>{field1:body}<div class="formClr"></div>{field1:validation}</td>
<td>{field1:description}</td>
</tr>
<tr class="rsform-block rsform-block-field2">
<td>{field2:caption}</td>
<td>{field2:body}<div class="formClr"></div>{field2:validation}</td>
<td>{field2:description}</td>
</tr>
<tr class="rsform-block rsform-block-calculate">
<td>{Calculate:caption}</td>
<td>{Calculate:body}<div class="formClr"></div>{Calculate:validation}</td>
<td>{Calculate:description}</td>
</tr>
<tr class="rsform-block rsform-block-total">
<td>{Total:caption}</td>
<td>{Total:body}<div class="formClr"></div>{Total:validation}</td>
<td>{Total:description}</td>
</tr>
</table>

javascript code

function calculateText(){

var op1=document.getElementById('field1');

var op2=document.getElementById('field2');

var result=document.getElementById('Total');

if(op1.value=="" || op1.value!=parseFloat(op1.value)) op1.value=0;

if(op2.value=="" || op2.value!=parseFloat(op2.value)) op2.value=0;

result.value=0;

result.value=parseInt(result.value);

result.value=parseInt(result.value)+parseInt(op1.value)+parseInt(op2.value);}


How do I
5x7 =35
35x1.5$
result:52.5$

field1 x field2 hidden = ?? x 1.5
total : 00

please help me :(

zealouss
03-18-2014, 02:56 PM
Replace last three lines of code with this one. Actually we have to explicitly convert field value to numbers

result.value = Number(op1.value) + Number(op2.value);