Home > database >  this.checked cannot be modified with checkbox click
this.checked cannot be modified with checkbox click

Time:05-27

It seems that the checked property of a checkbox cannot be modified, when the event is from the checkbox itself. Here is small example:

<input type="checkbox" onclick="this.checked=true; return false">

The checkbox is not checked after click. Why is this.checked=true ignored?

CodePudding user response:

It's happening because you're returning false. This value is assigned as the input value. Try this way:

<input type="checkbox" onclick="this.checked=true">
  • Related