elmas156 Posted April 22, 2011 Share Posted April 22, 2011 Hello everyone, I don't know much about javascript but I managed to put the following code together: <head> <script type="text/javascript"> function checkValue() { var linkemail=document.forms["theForm"]["linkemail"].value if (linkemail == 'y') { document.getElementById('xtraInfo').style.display=''; } else { document.getElementById('xtraInfo').style.display='none'; } } </script> </head> <body> <form id="theForm" name="theForm" method="post" action=""> <input type="checkbox" name="linkemail" value="y" onClick="return checkValue(this)" /> Check here to link your email. <div id="xtraInfo" style="display:none;"> Email <input name="name" type="text" id="name" /> </div> </form> </body> I'm trying to get the textbox to show when the checkbox is selected (which DOES work) and the textbox to disappear when the checkbox is deselected (which is where I'm having the trouble. Can anyone help me figure this out please?... Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/234405-hideshow-textbox-depending-on-checkbox-value/ Share on other sites More sharing options...
DavidAM Posted April 22, 2011 Share Posted April 22, 2011 I think you need to look at the checked attribute of the checkbox rather than the value. function checkValue() { var linkemail=document.forms["theForm"]["linkemail"].checked if (linkemail) { document.getElementById('xtraInfo').style.display=''; } else { document.getElementById('xtraInfo').style.display='none'; } } Quote Link to comment https://forums.phpfreaks.com/topic/234405-hideshow-textbox-depending-on-checkbox-value/#findComment-1204747 Share on other sites More sharing options...
elmas156 Posted April 22, 2011 Author Share Posted April 22, 2011 That works! Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/234405-hideshow-textbox-depending-on-checkbox-value/#findComment-1204833 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.