How to enable disable TextBox on CheckBox click in JavaScript?
<span>Do you have Passport?</span> <input id="chkConfirm" type="checkbox" onclick="EnableDisableTextBox()" /><hr /> <input id="txtPassportNumber" type="text" disabled="disabled" />
Hi Adnaan,
Use the removeAttribute and setAttribute for removing and adding disabled attribute to TextBox when CheckBox is checked or unchecked.
Refer below example.
HTML
<html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> <span>Do you have Passport?</span> <input id="chkConfirm" type="checkbox" onclick="EnableDisableTextBox()" /><hr /> <input id="txtPassportNumber" type="text" disabled="disabled" /> <script type="text/javascript"> function EnableDisableTextBox() { var txtPassportNumber = document.getElementById("txtPassportNumber"); if (document.getElementById("chkConfirm").checked) { txtPassportNumber.removeAttribute("disabled"); } else { txtPassportNumber.setAttribute("disabled", "disabled"); } } </script> </body> </html>
Demo
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.