Snippet. JavaScript. How to Find, if a Chekbox is Checked or Not

This little JavaScript snippet shows how to find, if a checkbox is checked or not.

<input type="checkbox" onclick="if(this.checked==true) { on_checked(); } else { on_not_checked(); }">

Example

This example shows a download button, if the user accepts the terms and conditions.

<input type="checkbox" onclick="if(this.checked==true) { document.getElementById('button_download').style.display = 'block'; } else { document.getElementById('button_download').style.display = 'none'; }"> Do you agree with the Terms and Conditions?
<button id="button_download" style="display:none;">Download

Test

Do you agree with the Terms and Conditions?

Updated on: 23 Nov 2024