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 checked
    if (this.checked) {
      // get value of current checkbox
      alert(this.value);
    }
  });
});
<!DOCTYPE html>
<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>

<body>
  <div class="checkbox">
    <label>first
      <input type="checkbox" value="1">
    </label>
    <label>second
      <input type="checkbox" value="2" onclick="">
    </label>
    <label>third
      <input type="checkbox" value="3">
    </label>
  </div>
</body>

</html>

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


Solution 2:


Solution 3:

window.jQuery(document).ready(function() {
    $('body').on('change', "input[type='checkbox']", function() {
        if (this.checked) {
            // get value of current checkbox
            alert(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"