Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

Cannot get javascript to enable a disabled submit button

So I have a submit button that I have disabled using the following:
<body onload="document.aasurvey.saveForm.disabled=true">

This part works, when the page loads the button is disabled. The part that's not working is the script that enables the button when a checkbox is clicked, seen here (this is between the <head> tags):
<script type="text/javascript">
function checkTerms() {

if(document.aasurvey.terms.checked==false)
{
document.aasurvey.saveForm.disabled=true;
}

else
{
document.aasurvey.saveForm.disabled=false;
}
}
</script>

And here are the related parts of the form:
<form id="aasurvey" name="aasurvey" class="appnitro"  method="post" action="submit.php">

<input id="terms" name="terms" onclick="checkTerms()" class="element checkbox" type="checkbox" value="1" />
<label class="choice" for="element_8_1">I certify that the statements I have made on this form are true and correct and without material omission.  This form is kept strictly confidential and will not be disclosed to anyone.</label>

<input id="saveForm" class="button_text" type="submit" name="saveForm" value="Submit" />

No matter what I try I can't get the button enabled after clicking the checkbox. If anyone can help it would be greatly appreciated!
0
ITNC
Asked:
ITNC
1 Solution
 
amit_gCommented:
Try changing

<input id="terms" name="terms" onclick="checkTerms()" class="element checkbox" type="checkbox" value="1" />

to

<input id="terms" name="terms" onclick="this.form.saveForm.disabled=!this.checked;" class="element checkbox" type="checkbox" value="1" />
0
 
MacAnthonyCommented:
Works for me. Do you have some other error in the form like another element with the id="terms" in it or something?

http://jsfiddle.net/MacAnthony/PpX7g/
0
 
ITNCAuthor Commented:
My code was working, the problem was being caused by another script I had attached to that page. The site that MacAnthony showed me (jsfiddle.net) is amazing and confirmed my syntax was correct.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now