0

I have a page with multiple checkboxes in varying states (checked or unchecked) . I'm trying to enable a button as soon as any of the checkbox values change state.

Here is my code so far but it doesn't seem to work properly yet:

var checkboxes = $("input[type='checkbox']");
   	
checkboxes.change(function(){
    $('#saveChanges').prop('enabled', true);
});

6
  • so what is the problem? do you mean when at least one of the checkbox is checked? Commented Jan 25, 2016 at 5:01
  • 2
    $('#saveChanges').prop('disabled', false); Commented Jan 25, 2016 at 5:05
  • Why aren't you posting a MCVE? Commented Jan 25, 2016 at 5:05
  • 1
    jsfiddle.net/arunpjohny/tbt1n236/1 ? Commented Jan 25, 2016 at 5:06
  • I don't understand the question - could you try to be more specific on your desired outcome Commented Jan 25, 2016 at 5:08

3 Answers 3

2
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>

<script>

    $(document).ready(function () {


        $("input[type='checkbox']").change(function () {

            $('#saveChanges').prop('disabled', false);

        });

 });  
</script>
</head>
<body>


  <input type="checkbox" value="1" />
<input type="checkbox" value="1" />
<input type="checkbox" value="1" />
<button id="saveChanges" disabled>Save</button>

</body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

Doesn't seem to work. I need to enable the button if any of the checkboxes change. jsfiddle.net/Lgop8aqp
@kernelpanic You forgot to add JQuery in the jsfiddle--> https://jsfiddle.net/Lgop8aqp/2/
1

Try, where submit button would be..

<input type="submit" value="Do thing" disabled>
var checkboxes = $("input[type='checkbox']"),
    submitButt = $("input[type='submit']");
checkboxes.click(function() {
    submitButt.attr("disabled", !checkboxes.is(":checked"));
});

Comments

0

Try,

<input class="myCheckBox" type="checkbox" value="true">
<input class="myCheckBox" type="checkbox" value="true">
<button type="submit" id="confirmButton">BUTTON</button>

var checkboxes = $('.myCheckBox');

checkboxes.on('change', function () 
{
    $('#confirmButton').prop('disabled', !checkboxes.filter(':checked').length);
}).trigger('change');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.