Javascript checkbox onChange

后端 未结 10 1203
孤街浪徒
孤街浪徒 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:24

    If you are using jQuery.. then I can suggest the following: NOTE: I made some assumption here

    $('#my_checkbox').click(function(){
        if($(this).is(':checked')){
            $('input[name="totalCost"]').val(10);
        } else {
            calculate();
        }
    });
    

提交回复
热议问题