By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,500 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

Calculating probability only works on the last box

P: 8
I have a PHP and javascript code to take value from two text boxes and calculate on triggering the "OnBlur" function and display in the third box.

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
  1. //here is the code.
  2.  
  3. //code for the text boxes.
  4. <td class="bodyForm"><input type="text" name="ITEM_IN[<?php echo $x;?>][PERCENTAGE_GO]" maxlength="10" size="3"<?php 
  5. if (!empty($_REQUEST['ITEM_IN'][$i]['PERCENTAGE_GO'])) {
  6. echo ' value="' . $_REQUEST['ITEM_IN'][$i]['PERCENTAGE_GO'] . '"';
  7. }
  8. //$go= $_REQUEST['ITEM_IN'][$i]['PERCENTAGE_GO'] ;?> /></td>
  9. <td class="bodyForm"><input type="text" onBlur="probability()" name="ITEM_IN[<?php echo $x;?>][PERCENTAGE_WIN]" maxlength="10" size="3"<?php 
  10. if (!empty($_REQUEST['ITEM_IN'][$i]['PERCENTAGE_WIN'])) {
  11. echo ' value="' . $_REQUEST['ITEM_IN'][$i]['PERCENTAGE_WIN'] . '"';
  12. }
  13.  
  14. //to display the results 
  15. <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 
  16. if (!empty($_REQUEST['ITEM_IN'][$i]['PROBABILITY'])) {
  17. echo ' value="' . $_REQUEST['ITEM_IN'][$i]['PROBABILITY'] . '"';
  18. }?>/></td>
  19.  
  20.  
  21.  
  22.  
  23. //javascript to calculate the probablity.
  24. <SCRIPT>
  25. function probability()
  26. {
  27. var val1 = parseInt(document.getElementById("ITEM_IN[<?php echo $x;?>][PERCENTAGE_GO]").value);
  28. var val2 = parseInt(document.getElementById("ITEM_IN[<?php echo $x;?>][PERCENTAGE_WIN]").value);
  29. var ansd = document.getElementById("ITEM_IN[<?php echo $x;?>][PROBABILITY]");
  30. ansd.value = Math.round((val1 * val2)/100);
  31. }
  32.  
  33. </SCRIPT>
[Please use CODE tags when posting source code. Thanks! --pbmods]

Please help.

Thanks
Jun 20 '07 #1
Share this Question
Share on Google+
1 Reply


pbmods
Expert 5K+
P: 5,821
Changed thread title to better describe the problem.
Jun 20 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.