jim.davidson Posted February 27, 2009 Share Posted February 27, 2009 I have checkbox "Other" that if the user checkes it a text field will open. I get that to work, but if the user unchecks it the text box doesn't go away. Can someone tell me what I'm missing? Here's the code. By the way I'm a newbie with javascript so the code might seem messy to you pros <input name="checkbox_other" type="checkbox" class="text_background" id="checkbox_other" value="other"onclick="(this.value=='other') ? document.getElementById('newClientLbl').style.display='' : document.getElementById('newClientLbl').style.display='none'"><label style="display:none" id="newClientLbl">Enter Your Client Type: <input type="text" name="newClient" class="text_background"></label> Any help will be appreciated Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 27, 2009 Share Posted February 27, 2009 Putting your javascript inline like that is not recommended and makes your code unwieldly. Just make a function that you can reuse if needed <html> <head> <script type="text/javascript"> function displayField(fieldID, display) { document.getElementById(fieldID).style.display = (display) ? 'inline' : 'none'; } </script> </head> <body> <input name="checkbox_other" type="checkbox" class="text_background" id="checkbox_other" value="other" onclick="displayField('newClientLbl', this.checked)"> <label style="display:none" id="newClientLbl">Enter Your Client Type: <input type="text" name="newClient" class="text_background"></label> </body> </html> Quote Link to comment Share on other sites More sharing options...
jim.davidson Posted February 27, 2009 Author Share Posted February 27, 2009 Thank you very much, that's what I was looking for and I appreciate the coding advice Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.