Jump to content

Recommended Posts

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!

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';
}	
}	

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.