Skip to content Skip to sidebar Skip to footer

How To Ensure A Different Option With Different Checkbox

I need to find solution for my site. I have more checkbox option and depending on the checkbox I decide to check I would like to get different option from the script. For example,

Solution 1:

try this

$(function() {
  $("input[type='checkbox']").change(function() {
    // check if currently click was to make it checkedif (this.checked) {
      // get value of current checkboxalert(this.value);
    }
  });
});
<!DOCTYPE html><html><head><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script></head><body><divclass="checkbox"><label>first
      <inputtype="checkbox"value="1"></label><label>second
      <inputtype="checkbox"value="2"onclick=""></label><label>third
      <inputtype="checkbox"value="3"></label></div></body></html>

alternate syntax $("input[type='checkbox']").on('click',function() {.... OR $("input[type='checkbox']").click(function() {....

Solution 2:

Try .change

e.g

$("#infos").change(function() {
    if(this.checked) {
        alert('infos is checked');
    }
});

Solution 3:

window.jQuery(document).ready(function() {
    $('body').on('change', "input[type='checkbox']", function() {
        if (this.checked) {
            // get value of current checkboxalert(this.value);
        }
    });
});

Solution 4:

I just tested and its worked now! my problem was solved with show(), hide() functions.

Post a Comment for "How To Ensure A Different Option With Different Checkbox"