compute sum dynamically with javascript

后端 未结 5 1933
耶瑟儿~
耶瑟儿~ 2021-01-22 20:57

I have two textboxes Num1 and Num2 and another textbox Sum having the value 10.

How can I do this wherein if the user

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-22 21:31

    
    
    
    
    
    function addNums() {
      var num1 = parseInt(document.getElementById('Num1').value,10);
      var num2 = parseInt(document.getElementById('Num2').value,10)
      document.getElementById('Sum').value = (num1 + num2).toString();
    }
    

    There are other ways to reference the form items, but this one works.

提交回复
热议问题