1

I have codes like this

<div class="checkbox">

            <input type="checkbox" id="checkme" value ="accept"/>
                        <label>I have read and agree to the terms and conditions</label>
                                    <p><input type="submit" name="submit" value="Order now!" id="sub1" disabled="disabled"/></p>

I was trying to put this Jscript below of codes:

<script>
$(document).ready(function() {
    var the_terms = $("#checkme");

    the_terms.click(function() {
        if ($(this).is(":checked")) {
            $("#sub1").removeAttr("disabled");
        } else {
            $("#sub1").attr("disabled", "disabled");
        }
    });
}); 
                        </script>

However it does not work at all. I already follow all guides on internet. Anyone can help what part i did wrong? Is there any additional codes beside these?'

Oh and this on php format

EDIT: Done this too

                                                    <script>
var checker = document.getElementById('checkme');
var sendbtn = document.getElementById('sub1');
checker.onchange = function() {
  sendbtn.disabled = !!this.checked;
};
                        </script>

But how do i change to disable when unchecked?

Community
  • 1
  • 1

2 Answers2

0

Simply use jquery change event like this :

$(document).ready(function() {

    $('#checkme').change(function() {
        if ($(this).is(":checked")) {
            $("#sub1").removeAttr("disabled");
        } else {
            $("#sub1").attr("disabled", "disabled");
        }
    });
}); 
Maha Dev
  • 3,915
  • 2
  • 31
  • 50
0
 $(function() {
  $('#id_of_your_checkbox').click(function() {
      if ($(this).is(':checked')) {
          $('#id_of_your_button').attr('disabled', 'disabled');
      } else {
          $('#id_of_your_button').removeAttr('disabled');
     }
  });
});
Shrikant
  • 538
  • 5
  • 15
  • http://stackoverflow.com/questions/6149917/disable-or-enable-submit-button-on-checkbox-checked-event – Shrikant Apr 06 '16 at 04:03
  • If you think another answer in its entirety covers this issue, you could have flagged it as a duplicate, instead of replicating the answer. Unless your answer is a modified version of the linked one, but that doesn't seem to be the case. – Reti43 Apr 06 '16 at 05:28