Enable and disable of text box through a checkbox
We may need to enable or disable a text box based on the input of the user by using disabled property of the element. For example we have some choices for the visitor and one of the options is Others. Once the visitor select the others options then ( only ) one text box will be enabled to allow the visitor to fill the details.
We have used the body onload command to keep the text area disabled while the page is loading.
Demo of Enable Disable text box
The full code is here.
<title>(Type a title for your page here)</title>
document.f1.other_text.disabled = status;
<form name=f1 method=post>
<input type="checkbox" name=others onclick="enable_text(this.checked)" >Others
<input type=text name=other_text>
Number of User Comments : 11
More on CheckBox & PHP
|I found everywhere this one.finally i found this by in this site.very simple and useful.good job.thank you.good luck.|
|how to use drop down list instead checkbox in this? |
|This works as described, but what if I want to have multiple disabled text fields linked to multiple checkboxes? The result for me is that checking ONE box enables ALL the text fields, but I would like it to only enable the one. Any ideas? Thanks!|
|this was helpful for me! thank you bro..|
|This Works.. Really superb..|
|can you help me how to disable submit button over the due date??|
|thanks it works perfect with textboxes but I also need to be able to enable/disable radio and dropboxes. Please could you tell me how to do this? I tried with your code and it didn't work :(|
|it should put in body or anywhere can put it ?|
i tested for secodn if it works i will coment again :D
|THANK FOR THIS ONE SIR|
What is the most important factor of a web site