1

I want to alert the value of a specific input[checkbox] when an input[checkbox] is checked. I have many input checkbox. so when it's checked, alert will fire.

<input type="checkbox" value="1">
<input type="checkbox" value="2">
<input type="checkbox" value="3">
....
John
  • 29
  • 1
  • 7

1 Answers1

2

Try this:

$('input[type="checkbox"]').change(function() {
  if ($(this).is(":checked")) {
    alert($(this).val())
    return;
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" value="1">
<input type="checkbox" value="2">
<input type="checkbox" value="3">
Chirag Jain
  • 1,367
  • 1
  • 11
  • 27
Jayesh Chitroda
  • 4,987
  • 13
  • 18