Go Premium for a chance to win a PS4. Enter to Win

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

Submit button greyed out until checkbox checked

How can I use Javascript to make a submit button greyed out until checkbox checked in the form?
0
a204801
Asked:
a204801
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
<input id="Submit" type="submit" disabled="disabled" value="Submit" />

<input type="checkbox" id="terms" onclick="if(this.checked) document.getElementById('Submit').removeAttribute('disabled');else document.getElementById('Submit').disabled = 'disabled'">

test page : http://jsfiddle.net/NspG7/
0
 
leakim971PluritechnicianCommented:
another one, just put the following in the head section : http://jsfiddle.net/NspG7/2/
<script language="javascript" type="text/javascript">
window.onload = function() {
    document.getElementById("terms").onchange = function() {
        if(this.checked) {
            document.getElementById('Submit').removeAttribute('disabled');
        }
        else {
            document.getElementById('Submit').disabled = 'disabled';
        }
    }
}
</script>

Open in new window


terms is the ID of your checkbox
Submit is the ID of your submit button
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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