fredowinz23 Posted August 24, 2008 Share Posted August 24, 2008 hi there... please give me the script how to disable the textbox if the check box is not check yet... please... i really need your help for our thesis Link to comment https://forums.phpfreaks.com/topic/121088-how-to-disable-textbox-if-the-checkbox-is-not-checked-yet/ Share on other sites More sharing options...
MasterACE14 Posted August 24, 2008 Share Posted August 24, 2008 I think you want javascript for this. Just google it. Were not here to hand out free scripts :-\ Link to comment https://forums.phpfreaks.com/topic/121088-how-to-disable-textbox-if-the-checkbox-is-not-checked-yet/#findComment-624229 Share on other sites More sharing options...
Ken2k7 Posted August 25, 2008 Share Posted August 25, 2008 Something like this? <input id='myCheckBox' type='checkbox' onclick='tehFunc();' /> <br /> <input id='myTextArea' type='text' disabled /> <script> function tehFunc() { document.getElementById("myTextArea").disabled = false; } </script> Link to comment https://forums.phpfreaks.com/topic/121088-how-to-disable-textbox-if-the-checkbox-is-not-checked-yet/#findComment-625334 Share on other sites More sharing options...
Psycho Posted August 25, 2008 Share Posted August 25, 2008 That script is not complete. It will enable the text field when the checkbox is first checked, but will not disable the field when it is unchecked. I would also add functionality to clear the value in the text field when the checkbox is unchecked. Try this: <html> <head> <script type="text/javascript"> function enableText(checkBool, textID) { textFldObj = document.getElementById(textID); //Disable the text field textFldObj.disabled = !checkBool; //Clear value in the text field if (!checkBool) { textFldObj.value = ''; } } </script> </head> <body> <input id="myCheckBox" type="checkbox" onclick="enableText(this.checked, 'myTextArea');" /> <br /> <input id="myTextArea" type="text" disabled="disabled" /> </body> </html> Link to comment https://forums.phpfreaks.com/topic/121088-how-to-disable-textbox-if-the-checkbox-is-not-checked-yet/#findComment-625370 Share on other sites More sharing options...
Ken2k7 Posted August 25, 2008 Share Posted August 25, 2008 That script is not complete. It will enable the text field when the checkbox is first checked, but will not disable the field when it is unchecked. I would also add functionality to clear the value in the text field when the checkbox is unchecked. Try this: <html> <head> <script type="text/javascript"> function enableText(checkBool, textID) { textFldObj = document.getElementById(textID); //Disable the text field textFldObj.disabled = !checkBool; //Clear value in the text field if (!checkBool) { textFldObj.value = ''; } } </script> </head> <body> <input id="myCheckBox" type="checkbox" onclick="enableText(this.checked, 'myTextArea');" /> <br /> <input id="myTextArea" type="text" disabled="disabled" /> </body> </html> Good call. Link to comment https://forums.phpfreaks.com/topic/121088-how-to-disable-textbox-if-the-checkbox-is-not-checked-yet/#findComment-625404 Share on other sites More sharing options...
smithveg Posted November 7, 2008 Share Posted November 7, 2008 Thanks for the code. Link to comment https://forums.phpfreaks.com/topic/121088-how-to-disable-textbox-if-the-checkbox-is-not-checked-yet/#findComment-684595 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.