Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable button when checkbox checked 1

Status
Not open for further replies.

fischadler

Programmer
Joined
May 31, 2002
Messages
258
Location
MT
I need to have a checkbox that is unchecked by default. I also have form submit button that I need to be disabled when the form is loaded. How can I have the button enabled as soon as the checkbox is ticked?

Thanks
 
Here is an example using IE

<html>
<head>
<script language=javascript>
function test(theField)
{
if(theField.checked)
{
document.getElementById(&quot;btnSubmit&quot;).disabled=false

}else
{
document.getElementById(&quot;btnSubmit&quot;).disabled=true
}


}

</script>
</head>
<body>
<form>
<input type=checkbox name=&quot;mycheck&quot; onclick=&quot;test(this)&quot;>
<input type=submit disabled=true name=&quot;btnSubmit&quot; id=&quot;btnSubmit&quot;>
</form>
</body>
</html>
 
Thanks for the information. The code works but there is a slight problem. If I hit the back button to go back the the page of the submit button, the checkbox is still checked but the button is disabled. If I uncheck the checkbox and re check it again, then the submit button becomes enabled. Is there a way to have the submit button still enabled when the user goes back to the submit site?(this is only needed when some fields are filled incorrectly but it happens occasionally.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top