coolguyraj
06-19-2007, 08:41 AM
Hi
I am trying to add multiple line items.
The line items contains two numeric fields a calculate "button" and a field that displays results after calculation .the input for the calculation is taken from the two numeric fields before the button.
There can be multiple line items like this.
I wanted help on javascript code to calculate and display the results on each line item.
here is my code.
//php code for display of the three field and button.//first numeric field
<td class="bodyForm"><input type="text" name="ITEM_IN[<?php echo $x;?>][PERCENTAGE_GO]" maxlength="10" size="3"<?php
if (!empty($_REQUEST['ITEM_IN'][$i]['PERCENTAGE_GO'])) {
echo ' value="' . $_REQUEST['ITEM_IN'][$i]['PERCENTAGE_GO'] . '"';
}
</td>
//second numeric field
<td class="bodyForm"><input type="text" name="ITEM_IN[<?php echo $x;?>][PERCENTAGE_WIN]" maxlength="10" size="3"<?php
if (!empty($_REQUEST['ITEM_IN'][$i]['PERCENTAGE_WIN'])) {
echo ' value="' . $_REQUEST['ITEM_IN'][$i]['PERCENTAGE_WIN'] . '"';
}</td>
//caculate button
<INPUT TYPE="button" VALUE="PROBABILITY" name="ITEM_IN[<?php echo $x;?>][PROBABLITY]" onclick="javascript:probablity()" style="font-size: 6pt"></th>
//to display results of the calclation for each line item.
<input type="text" id="ITEM_IN[<?php echo $x;?>][PROBABILITY]" name="ITEM_IN[<?php echo $x;?>][PROBABILITY]" size="5" readonly="readonly" value="<?php $_REQUEST['ITEM_IN'][$i]['PROBABILITY'];?>"</td>
//javascript function to calculate
<script>
function probablity()
{
var val1 = parseInt(document.getElementById("ITEM_IN[<?php echo $x;?>][PERCENTAGE_GO]").value);
var val2 = parseInt(document.getElementById("ITEM_IN[<?php echo $x;?>][PERCENTAGE_WIN]").value);
var ITEM_IN[<?php echo $x;?>][PROBABILITY]= document.getElementById("ITEM_IN[<?php echo $x;?>][PROBABILITY]");
ITEM_IN[<?php echo $x;?>][PROBABILITY].value = Math.round((val1 * val2)/100);
}
</script>
I am stuck up with this issue.Also not sure if my javascript code is right.
I am not able to display the results for each of the line item
Please help me.
Thanks.
I am trying to add multiple line items.
The line items contains two numeric fields a calculate "button" and a field that displays results after calculation .the input for the calculation is taken from the two numeric fields before the button.
There can be multiple line items like this.
I wanted help on javascript code to calculate and display the results on each line item.
here is my code.
//php code for display of the three field and button.//first numeric field
<td class="bodyForm"><input type="text" name="ITEM_IN[<?php echo $x;?>][PERCENTAGE_GO]" maxlength="10" size="3"<?php
if (!empty($_REQUEST['ITEM_IN'][$i]['PERCENTAGE_GO'])) {
echo ' value="' . $_REQUEST['ITEM_IN'][$i]['PERCENTAGE_GO'] . '"';
}
</td>
//second numeric field
<td class="bodyForm"><input type="text" name="ITEM_IN[<?php echo $x;?>][PERCENTAGE_WIN]" maxlength="10" size="3"<?php
if (!empty($_REQUEST['ITEM_IN'][$i]['PERCENTAGE_WIN'])) {
echo ' value="' . $_REQUEST['ITEM_IN'][$i]['PERCENTAGE_WIN'] . '"';
}</td>
//caculate button
<INPUT TYPE="button" VALUE="PROBABILITY" name="ITEM_IN[<?php echo $x;?>][PROBABLITY]" onclick="javascript:probablity()" style="font-size: 6pt"></th>
//to display results of the calclation for each line item.
<input type="text" id="ITEM_IN[<?php echo $x;?>][PROBABILITY]" name="ITEM_IN[<?php echo $x;?>][PROBABILITY]" size="5" readonly="readonly" value="<?php $_REQUEST['ITEM_IN'][$i]['PROBABILITY'];?>"</td>
//javascript function to calculate
<script>
function probablity()
{
var val1 = parseInt(document.getElementById("ITEM_IN[<?php echo $x;?>][PERCENTAGE_GO]").value);
var val2 = parseInt(document.getElementById("ITEM_IN[<?php echo $x;?>][PERCENTAGE_WIN]").value);
var ITEM_IN[<?php echo $x;?>][PROBABILITY]= document.getElementById("ITEM_IN[<?php echo $x;?>][PROBABILITY]");
ITEM_IN[<?php echo $x;?>][PROBABILITY].value = Math.round((val1 * val2)/100);
}
</script>
I am stuck up with this issue.Also not sure if my javascript code is right.
I am not able to display the results for each of the line item
Please help me.
Thanks.