The code works fine with one line item,If i have more that one line item.i will be able too calculate the value only for the last line item added ,But if i change any of the values in the two boxes from which it takes values.The probablity will not be recalculated.
Could anyone help me to fix this?
Expand|Select|Wrap|Line Numbers
- //here is the code.
- //code for the text boxes.
- <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'] . '"';
- }
- //$go= $_REQUEST['ITEM_IN'][$i]['PERCENTAGE_GO'] ;?> /></td>
- <td class="bodyForm"><input type="text" onBlur="probability()" 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'] . '"';
- }
- //to display the results
- <input type="text" id="answer" onBlur="probability()" name="ITEM_IN[<?php echo $x;?>][PROBABILITY]" size="5" value="<?php echo $_REQUEST['ITEM_IN'][$i]['PROBABILITY']?>" <?php
- if (!empty($_REQUEST['ITEM_IN'][$i]['PROBABILITY'])) {
- echo ' value="' . $_REQUEST['ITEM_IN'][$i]['PROBABILITY'] . '"';
- }?>/></td>
- //javascript to calculate the probablity.
- <SCRIPT>
- function probability()
- {
- 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 ansd = document.getElementById("ITEM_IN[<?php echo $x;?>][PROBABILITY]");
- ansd.value = Math.round((val1 * val2)/100);
- }
- </SCRIPT>
Please help.
Thanks