How to show hide TextBox on CheckBox click?
<span>Do you have Passport?</span> <input id="chkConfirm" type="checkbox" /><hr /> <input id="txtPassportNumber" type="text" style="display:none" />
Hi Adnaan,
Inside CheckBox click event handler, check if CheckBox is checked then show else hide the TextBox by setting the style attribute to block and none respectively.
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="ShowHideTextBox()" /><hr /> <input id="txtPassportNumber" type="text" style="display:none" /> <script type="text/javascript"> function ShowHideTextBox() { document.getElementById("txtPassportNumber").style.display = document.getElementById("chkConfirm").checked ? "block" : "none"; } </script> </body> </html>
Demo
Screenshot
Downloads
Download Sample
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.