Quantcast
Channel: Check if checkbox is checked with jQuery - Stack Overflow
Viewing all articles
Browse latest Browse all 28

Answer by Kamil Kiełczewski for Check if checkbox is checked with jQuery

$
0
0

Your question is not clear: you want to give "checkbox array id" at input and get true/false at output - in this way you will not know which checkbox was checked (as your function name suggest). So below there is my proposition of body of your isCheckedById which on input take checkbox id and on output return true/false (it's very simple but your ID should not be keyword),

this[id].checked

function isCheckedById(id) {
  return this[id].checked;
}

function check() {
  console.clear()
  console.log('1',isCheckedById("myCheckbox1"));
  console.log('2',isCheckedById("myCheckbox2"));
  console.log('3',isCheckedById("myCheckbox3"));
}
<label><input id="myCheckbox1" type="checkbox">check 1</label><label><input id="myCheckbox2" type="checkbox">check 2</label><label><input id="myCheckbox3" type="checkbox">check 3</label><!-- label around inputs makes text clickable --><br><button onclick="check()">show checked</button>

Viewing all articles
Browse latest Browse all 28

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>