How to change the value of a checkbox when it is checked or unchecked


Jonas Dulay

Hi all, here's the question. I want to perform other calculations based on checkboxes.

<div>
 COD: <input type="checkbox" id="trigger" name="question" >
</div>

this is the javascript used to calculate the price of the item the problem is that i don't know how to do the else if method

<script>
    $("#price,#quant,#shipment").keyup(function () {
      if(+myFunction3() =="" )
      {
        $('#demo').val(0);
      }
      else if($('#trigger')=="checked") //this is the problem
      {
        $('#demo').val($('#price').val() * $('#quant').val() ;
      }
      else
      {
      $('#demo').val($('#price').val() * $('#quant').val() + +myFunction3());
     }
  });
  </script>

Thank you in advance.

Jacob Peterson

With jQuery you can do the following:

else if($('#trigger:checked').length > 0)

or

else if($('#trigger').is(':checked'))

If you want to rerun the calculation when the user checks or unchecks the checkbox, you can run the same code that runs on the keyup function on the following keyboard:

$('#trigger').change(function() {
  ...
})

Related


Change the value of a checkbox when it is checked or unchecked

Sindhiya I have some checkboxes. There is a checkbox here for select all. When I check all the rest will check and the value becomes one. If I uncheck all checkboxes, it stays checked and the value becomes zero. Now, if the individual checkboxes need to be che

Change the value of a checkbox when it is checked or unchecked

Sindhiya I have some checkboxes. There is a checkbox here for select all. When I check all the rest will check and the value becomes one. If I uncheck all checkboxes, it stays checked and the value becomes zero. Now, if the individual checkboxes need to be che

Change the value of a checkbox when it is checked or unchecked

Sindhiya I have some checkboxes. There is a checkbox here for select all. When I check all the rest will check and the value becomes one. If I uncheck all checkboxes, it stays checked and the value becomes zero. Now, if the individual checkboxes need to be che

Change variable value when checkbox is checked/unchecked

username I am trying to change the value of a variable based on the state of a checkbox, here is my code sample <script type="text/javascript"> if(document.getElementByType('checkbox').checked) { var a="checked";} else{ var a="not checked";} document.getElemen

Change the value of a checkbox when it is checked or unchecked

Sindhiya I have some checkboxes. There is a checkbox here for select all. When I check all the rest will check and the value becomes one. If I uncheck all checkboxes, it stays checked and the value becomes zero. Now, if the individual checkboxes need to be che

Change the value of a checkbox when it is checked or unchecked

Sindhiya I have some checkboxes. There is a checkbox here for select all. When I check all the rest will check and the value becomes one. If I uncheck all checkboxes, it stays checked and the value becomes zero. Now, if the individual checkboxes need to be che

Change the value of a checkbox when it is checked or unchecked

Sindhiya I have some checkboxes. There is a checkbox here for select all. When I check all the rest will check and the value becomes one. If I uncheck all checkboxes, it stays checked and the value becomes zero. Now, if the individual checkboxes need to be che

Change the value of a checkbox when it is checked or unchecked

Sindhiya I have some checkboxes. There is a checkbox here for select all. When I check all the rest will check and the value becomes one. If I uncheck all checkboxes, it stays checked and the value becomes zero. Now, if the individual checkboxes need to be che

Change variable value when checkbox is checked/unchecked

username I am trying to change the value of a variable based on the state of a checkbox, here is my code sample <script type="text/javascript"> if(document.getElementByType('checkbox').checked) { var a="checked";} else{ var a="not checked";} document.getElemen

asp: checkbox color change when checked or unchecked

Suyash Gupta I have a checkbox in a GridView and I want to change its color to red when unchecked and green when checked . How can I do this? <ItemTemplate> <asp:CheckBox ID="checkboxAttendanceStatus" BackColor="Red" runat="server" AutoPostBack="true" /> </

asp: checkbox color change when checked or unchecked

Suyash Gupta I have a checkbox in a GridView and I want to change its color to red when unchecked and green when checked . How can I do this? <ItemTemplate> <asp:CheckBox ID="checkboxAttendanceStatus" BackColor="Red" runat="server" AutoPostBack="true" /> </

asp: checkbox color change when checked or unchecked

Suyash Gupta I have a checkbox in a GridView and I want to change its color to red when unchecked and green when checked . How can I do this? <ItemTemplate> <asp:CheckBox ID="checkboxAttendanceStatus" BackColor="Red" runat="server" AutoPostBack="true" /> </

asp: checkbox color change when checked or unchecked

Suyash Gupta I have a checkbox in a GridView and I want to change its color to red when unchecked and green when checked . How can I do this? <ItemTemplate> <asp:CheckBox ID="checkboxAttendanceStatus" BackColor="Red" runat="server" AutoPostBack="true" /> </

Change disable/enable when checkbox is checked/unchecked

Zock I want to combine these two jquery things: disable/enable jquery input? and jQuery to check if checkbox is not checked HTML: <label> <input type="checkbox" name="agreement"> I read all the information in the red box above and followed the instructions

asp: checkbox color change when checked or unchecked

Suyash Gupta I have a checkbox in a GridView and I want to change its color to red when unchecked and green when checked . How can I do this? <ItemTemplate> <asp:CheckBox ID="checkboxAttendanceStatus" BackColor="Red" runat="server" AutoPostBack="true" /> </

asp: checkbox color change when checked or unchecked

Suyash Gupta I have a checkbox in a GridView and I want to change its color to red when unchecked and green when checked . How can I do this? <ItemTemplate> <asp:CheckBox ID="checkboxAttendanceStatus" BackColor="Red" runat="server" AutoPostBack="true" /> </

asp: checkbox color change when checked or unchecked

Suyash Gupta I have a checkbox in a GridView and I want to change its color to red when unchecked and green when checked . How can I do this? <ItemTemplate> <asp:CheckBox ID="checkboxAttendanceStatus" BackColor="Red" runat="server" AutoPostBack="true" /> </

asp: checkbox color change when checked or unchecked

Suyash Gupta I have a checkbox in a GridView and I want to change its color to red when unchecked and green when checked . How can I do this? <ItemTemplate> <asp:CheckBox ID="checkboxAttendanceStatus" BackColor="Red" runat="server" AutoPostBack="true" /> </