Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performing Arithmetic Calculation In Selectboxs Using Javascript

I have a case something like this:

enter image description here

How can I do when choose example A = 3 and B = 5, will update 8 in column C automatically, and so on for different column and rows ?

The help will be very appreciated. Thank you in advanced !

like image 793
Philips Tel Avatar asked Nov 26 '25 16:11

Philips Tel


1 Answers

Try this:

  1. Call the select boxes like "a1", "a2", "b1", "b2"

  2. Call the cells in C like "c1", "c2"

  3. Make the onchange event of the select boxes be like this:

    function update() {
        var id = this.id.substring(1);
        var value1 = parseInt(document.getElementById("a" + id).value);
        var value2 = parseInt(document.getElementById("b" + id).value);
        document.getElementById("c" + id).innerHTML = value1 + value2;
    }
    
like image 97
PurkkaKoodari Avatar answered Nov 28 '25 07:11

PurkkaKoodari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!