Javascript checkbox onChange

后端 未结 10 1193
孤街浪徒
孤街浪徒 2020-11-28 06:00

I have a checkbox in a form and I\'d like it to work according to following scenario:

  • if someone checks it, the value of a textfield (totalCost)
10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 06:43

    try

    totalCost.value = checkbox.checked ? 10 : calculate();
    

    function change(checkbox) {
      totalCost.value = checkbox.checked ? 10 : calculate();
    }
    
    function calculate() {
      return other.value*2;
    }
    input { display: block}
    Checkbox: 
    Total cost: 
    Other: 

提交回复
热议问题