Categories
JavaScript Answers

How to make a checkbox read only with HTML and JavaScript?

Spread the love

Sometimes, we want to make a checkbox read only with HTML and JavaScript.

In this article, we’ll look at how to make a checkbox read only with HTML and JavaScript.

How to make a checkbox read only with HTML and JavaScript?

To make a checkbox read only with HTML and JavaScript, we return false when we click on the checkbox.

For instance, we write

<input type="checkbox" onclick="return false" />

to set onclick to return false` to stop clicks from modifying the checkbox’s state.

Conclusion

To make a checkbox read only with HTML and JavaScript, we return false when we click on the checkbox.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *