Note that there are some explanatory texts on larger screens.

plurals
  1. PODisable submit if checkbox value has not changed from initial page-render
    primarykey
    data
    text
    <p>I have a script that does not allow submit until the form value is changed from the initial page-render.</p> <p>Everything works, except for the radio buttons. When I try to check or uncheck them, they have no effect on the button.</p> <p>Anyone see what is wrong? (I want to do a check to see if one or more of the checkboxes has changed from the initial page-render)</p> <pre><code>$(document).ready(function () { var button = $('#submit-data'); $('input, select, checkbox').each(function () { $(this).data('val', $(this).val()); }); $('input, select, checkbox').bind('keyup change blur', function () { var changed = false; $('input, select, checkbox').each(function () { if ($(this).val() != $(this).data('val')) { changed = true; } }); $('#submit-data').prop('disabled', !changed); }); }); </code></pre> <h1>Edit:</h1> <p>Checkbox html:</p> <pre><code>&lt;input checked="checked" id="contactemail" name="contactemail" type="checkbox" /&gt; &lt;input id="contactsms" name="contactsms" type="checkbox" /&gt; &lt;input checked="checked" id="contactphone" name="contactphone" type="checkbox" /&gt; </code></pre> <h1>Edit 2:</h1> <p>New code from answer from Marikkani Chelladurai. It is almost working, but it only works if the checkbox is not checked initially, and then checked by the user. <a href="http://jsfiddle.net/7YLGa/2/" rel="nofollow">Link to JSFiddle</a></p> <pre><code>$(document).ready(function() { var button = $('#submit-data'); $('input, select').each(function () { $(this).data('val', $(this).val()); }); $('input[type=radio], input[type=checkbox]').each(function (e) { $(this).data('val', $(this).attr('checked')); }); //For radio buttons $('input, select').bind('keyup change blur', function (e) { var changed = false; if (e.target.type == "radio" || e.target.type == "checkbox" ) { if($(this).data('val') != $(this).attr('checked')){ changed = true; } } else { if ($(this).val() != $(this).data('val')) { changed = true; } } $('#submit-data').prop('disabled', !changed); }); }); </code></pre> <p><a href="http://jsfiddle.net/7YLGa/2/" rel="nofollow">Link to JSFiddle</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload