Search code examples
javascriptjqueryinputliveonkeyup

Total sum of live changinput values


At first I have to apologize for my English. Im not native speaker.

Im a beginner and dont know JS or jQuery extensions well. Need to sum 3 input live changing values with unique ID.

I wish sum these values live too. So i have to write something like

total = $('#sumOne').value+$('#sumTwo').value+$(#sumThree).value

As I said, i really dont know JS, i know that the row above is absolutely incorrect.

Could anyone help me and write some example of script?

Thanks a lot for your time and advice.


Solution

  • parseInt($('#sumOne').val())+parseInt($('#sumTwo').val())+parseInt($(#sumThree).val());
    

    You want:

    this.value = ''; // straight JS, no jQuery
    

    or

    $(this).val(''); // jQuery
    

    With $(this).value = '' you're assigning an empty string as the value property of the jQuery object that wraps this -- not the value of this itself.

    reference val()