kwilliams Posted February 24, 2006 Share Posted February 24, 2006 I'm using JavaScript set the disable property on a textbox if a checkbox is selected, like this:<input type="checkbox" name="cbquestion1" id="cbquestion1" onclick="java script:document.form1.txtanswer1.disabled=false">What is the name of your favorite pet?</input><input type="text" id="txtanswer1" name="txtanswer1" value="" size="20" maxlength="20" disabled="true" />It works great, but now I'd like to add a behavior will basically do the opposite so that if the checkbox is then de-selected after initially being selected, it will re-disable the textbox. If anyone knows how to do this, I'd greatly appreciate the help. Thanks. Link to comment Share on other sites More sharing options...
scott100 Posted February 24, 2006 Share Posted February 24, 2006 I've ammended the code slightly but it does what you want <head><script>function check(){ var val=document.getElementById('cbquestion1').checked if(val==true)document.getElementById('txtanswer1').disabled = false; else document.getElementById('txtanswer1').disabled = true;}</script></head><body><input onclick="check()" type="checkbox" name="cbquestion1" id="cbquestion1" />What is the name of your favorite pet?<input type="text" id="txtanswer1" name="txtanswer1" value="" size="20" maxlength="20" disabled="disabled" /></body> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now