Top community members
All Wiki Articles Create Wiki Article

Many years me and my friends we were volunteers on my university doing programming classes for young people.

I got main conclusion: Young people are awesome, especially students, because they always bring new and fresh ideas :)
* I loved to do it but my time is limited

  I decided to create something that will help millions of students

Now I am here

co-founder

JavaScript - onchange event for input checkbox element example

0 contributions
1 points

In this article few ways how to handle change event for input checkbox element has been described.

1. onchange attribute example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <label>
  	<input type="checkbox" onchange="onChange(this)" /> Agreement
  </label>
  <script>

    function onChange(element) {
    	console.log('Agreement changed to ' + element.checked + ' by onchange event.');
    }

  </script>
</body>
</html>

2. onchange property example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <label>
  	<input id="agreement" type="checkbox" /> Agreement
  </label>
  <script>

    var agreement = document.getElementById('agreement');

    agreement.onchange = function(element) {
    	console.log('Agreement changed to ' + agreement.checked + ' by onchange event.');
    };

  </script>
</body>
</html>

3. addEventListener method example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <label>
  	<input id="agreement" type="checkbox" /> Agreement
  </label>
  <script>

    var agreement = document.getElementById('agreement');

    agreement.addEventListener('change', function(element) {
    	console.log('Agreement changed to ' + agreement.checked + ' by change event.');
    });

  </script>
</body>
</html>

 

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey ūüĎč
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more