Click here to Skip to main content
14,640,670 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi guys.
I basically want the button to be disabled if the user does not check the check box.
I dont know why it isnt working, not even recognising my button id

Here's my code:

            <input type="checkbox" name="one" id="one"/>
            <label for="one">I have read and I accept the terms and conditions</label>
            <br />

<div class="col-sm-12">
            <button type="submit" name="btnnext" id="btnnext" class="btn btn-primary btn-primary">Next<span class="glyphicon glyphicon-chevron-right"></span></button>

<script type="text/javascript">
        var checkBoxes = $('one');
        checkBoxes.change(function () {
        $('#btnnext').prop('disabled', checkBoxes.filter(':checked').length < 1);
Updated 6-Sep-15 20:15pm
Rate this:
Please Sign up or sign in to vote.

Solution 2

Click Here...Feel Free ...And Start Work...[^]
InvisibleMedia 7-Sep-15 2:41am
Hi, the sample code given in this link does not use jQuery.
but, the question talk about it
Rate this:
Please Sign up or sign in to vote.

Solution 3

Selector $('one') is wrong, should be $('#one'), by id. For selecting by name, you can use attribute selectors.
Please see:[^].

This is the first bug I can see immediately, there can be some other problems; I did not check up the whole thing.
Also, see the main pattern if jQuery use here:[^].

Rate this:
Please Sign up or sign in to vote.

Solution 1


inline scripts should not be used...objects could be not loaded yet.
I suggest you use :

body.onload(function() { ... checkBoxes.change();});
Janine_A 6-Sep-15 15:53pm
Thanks. Where do add that? havent used that before
Janine_A 6-Sep-15 15:57pm
How will i go about implementing that?
InvisibleMedia 6-Sep-15 16:14pm
write it into the <head> node, add <script language="Javascript" type="text/javascript">body.onload(...);</script>
Janine_A 6-Sep-15 17:29pm
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100