Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

HTML
            <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>
        </div>

<script type="text/javascript">
        var checkBoxes = $('one');
        checkBoxes.change(function () {
        $('#btnnext').prop('disabled', checkBoxes.filter(':checked').length < 1);
        });
        checkBoxes.change();
    </script>
Posted
Updated 6-Sep-15 20:15pm
v2

Click Here...Feel Free ...And Start Work...https://www.hscripts.com/scripts/JavaScript/enable-submit.php[^]
 
Share this answer
 
Comments
InvisibleMedia 7-Sep-15 2:41am    
Hi, the sample code given in this link does not use jQuery.
but, the question talk about it
Selector $('one') is wrong, should be $('#one'), by id. For selecting by name, you can use attribute selectors.
Please see: http://api.jquery.com/category/selectors[^].

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: https://learn.jquery.com/about-jquery/how-jquery-works[^].

—SA
 
Share this answer
 
Hi,

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

JavaScript
body.onload(function() { ... checkBoxes.change();});
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900