Submit button greyed out until checkbox checked

a204801
a204801 used Ask the Experts™
on
How can I use Javascript to make a submit button greyed out until checkbox checked in the form?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
<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/
leakim971Multitechnician
Top Expert 2014

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial