0

I have this problem that I add 8 textbox and it works fine but when i add more textbox like 16 textbox it doesnt add the last textbox. does anyone encoutered this problem? Thanks in Advance.

Live Link: JAVASCRIPT.

function sum() {

        var basicpay = document.getElementById('basicpay').value;
        var overtime = document.getElementById('overtime').value;
        var regularholiday = document.getElementById('regularholiday').value;
        var specialholiday = document.getElementById('specialholiday').value;
        var allowanceday = document.getElementById('allowanceday').value;
        var others = document.getElementById('others').value;
        var grosspay = document.getElementById('grosspay').value;
        var monthpay13 = document.getElementById('monthpay13').value;
        var absent = document.getElementById('absent').value;
        var tardiness = document.getElementById('tardiness').value;
        var sss = document.getElementById('sss').value;
        var pagibig = document.getElementById('pagibig').value;
        var philhealth = document.getElementById('philhealth').value;
        var cashadvances = document.getElementById('cashadvances').value;
        var withholdingtax = document.getElementById('withholdingtax').value;
        var others = document.getElementById('others').value;



        var result = 

        parseInt(basicpay) + 
        parseInt(overtime) +
        parseInt(regularholiday) +
        parseInt(specialholiday) +
        parseInt(allowanceday) +
        parseInt(others) +
        parseInt(grosspay) +
        parseInt(absent) + 
        parseInt(tardiness) +
        parseInt(sss) +
        parseInt(pagibig) +
        parseInt(philhealth) +
        parseInt(cashadvances) +
        parseInt(withholdingtax) +
        parseInt(others) +
        parseInt(monthpay13);

        if (!isNaN(result)) {
            document.getElementById('totalincome').value = result;
        }
        }
1
  • Why are you setting others twice and adding it two times in the result formula? Commented Jul 19, 2014 at 9:23

3 Answers 3

1

The problem is that you're using the same ID others for field 6 and field 16. Give them different IDs

16.<input type="text" id="others1" Placeholder="More others"  onkeyup="sum();" /><br>

And change the JS:

var others1 = var others = document.getElementById('others1').value;

var result = 

parseInt(basicpay) + 
parseInt(overtime) +
parseInt(regularholiday) +
parseInt(specialholiday) +
parseInt(allowanceday) +
parseInt(others) +
parseInt(grosspay) +
parseInt(absent) + 
parseInt(tardiness) +
parseInt(sss) +
parseInt(pagibig) +
parseInt(philhealth) +
parseInt(cashadvances) +
parseInt(withholdingtax) +
parseInt(others1) +
parseInt(monthpay13);
Sign up to request clarification or add additional context in comments.

Comments

0

I think that problem is because your 6 and 16 number textbox has same ID.

Change your ID of textbox number 16 and It should work.

1 Comment

HAHAHAHAHA! NICE ONE SIR! CASE CLOSE! Thanks Alot guys!
0

The issue happens on the very last field. This is caused by the fact that you have two boxes with the same ID. To fix that change the last box ID from others to others2. And also change your variable called others to others2 because there are two variables called others

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.