473,491 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calculating probability only works on the last box

8 New Member
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
1 1638
pbmods
5,821 Recognized Expert Expert
Changed thread title to better describe the problem.
Jun 20 '07 #2

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

Similar topics

5
8789
by: Ron Adam | last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone here for a great programming language. Below is my first Python program (not my first program) and I'd apreciate any...
5
2965
by: Sarah Wang | last post by:
Hello everyone! I want to calculate zprob(the area under the normal curve) with python and I managed to find a function from the internet. But the problem is that the function calculates the...
25
5128
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
1
1699
by: Richard Fleming | last post by:
hi, i need to write a probability engine that works out the score in a football match based on player stats, formation, weather etc. I dont even know how to use probability in c..... so please can...
11
4199
by: Mayank Kaushik | last post by:
hi everyone, im trying to create a function that generates a 1 or a 0, with the probability of a 1 being generated equal to X (which is passed to the function as a parameter). any ideas?...
8
2741
by: Elliot Temple | last post by:
Problem: Randomly generate 10 integers from 0-100 inclusive, and sum them. Do that twice. What is the probability the two sums are 390 apart? I have code to do part of it (below), and I know how...
3
1736
by: laurentc | last post by:
Dear all, I have a simple table, with only the following fields: - Key - MyDate - Price I would like to biuld a Query which uses these fields and which make some
10
3768
by: Lisa | last post by:
In translating the formula for calculating lottery odds for various conditions into a Visual Basic Program, I have apparently missed something in that I get errors in the part of the calculation...
5
8790
by: cbalian | last post by:
I am looking for a TSQL code that would calculate a specific date each month that varies based on the following condition: I need the result that would return the date of the Thursday after the...
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.