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

# How to calculate in multiple line items?

 P: 8 I have a 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? //here is the code. //code for the text boxes.
/> />
//javascript to calculate the probablity. Please help. Thanks Jun 20 '07 #1
Share this Question
3 Replies

 Expert Mod 15k+ P: 16,027 Could you give the HTML source that is generated (not PHP), i.e. what values are generated by the PHP code? Also, give an example of at least two rows, so we can work with that. Jun 20 '07 #2

 P: 8 Hi , Thanks for your replay,Below is the generated HTML code. HTML FOR FIRST LINE ITEM tr class="headerBG">
% Go % Win Probability
% Go % Win Probability % Go % Win Probability
//THIS TEXT BOX DISPLAYS CACULATED VALUE FOR THIRD LINE ITEM
//THIS TEXT BOX DISPLAYS CACULATED VALUE FOR FIRST LINE ITEM //SECOND LINE ITEM //THIS TEXT BOX DISPLAYS CACULATED VALUE FOR SECOND LINEITEM //SECOND LINE ITEM (Button to add new Line Item) (Button to Submit the Line items) Let me know if you have more clarification. Thanks. Jun 21 '07 #3

 Expert Mod 15k+ P: 16,027 You're overwriting probability. Instead have one generic function which takes a parameter (say, index). Then modify as below: Expand|Select|Wrap|Line Numbers function probability(index) { var val1 = parseInt(document.getElementById("ITEM_IN["+index+"][PERCENTAGE_GO]").value); var val2 = parseInt(document.getElementById("ITEM_IN["+index+"][PERCENTAGE_WIN]").value); var ansd = document.getElementById("ITEM_IN["+index+"][PROBABILITY]"); ansd.value = Math.round((val1 * val2)/100); } Notice how I have replaced 0, 1, 2, etc. with 'index'. When you call the function, call it with 0,1,2,etc. Jun 21 '07 #4

### Post your reply

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