Checkbox state based on text field value
<p>I have a search form with many checkboxes with class='cambio', and a hidden field with id #cambio too.</p>

<p>This is how the form works:</p>

<ol>
<li>When a checkbox is checked, his value is sent to this hidden input.</li>
<li>This hidden input is disabled by default and get enabled only if a value is set.</li>
<li>I get the default value for this field with $_GET['cambio'], so I can keep the form update on page load.</li>
</ol>

<p>The problem is when I load the page, I get the default values right on my hidden input, but the related checkboxes are all unchecked.</p>

<p>My question is: How I can set these checkboxes to 'checked' only if his value is present on the hidden input?</p>

<p>Here is my code:</p>

<pre><code>jQuery(function($) {
$("input:checkbox.cambio").change(function() {
    var newArr = $("input:checkbox.cambio:checked").map(function() { return this.value; });
    $("#cambio").val(newArr.get());

    if($('#cambio').val() !== "") {
    $('#cambio').prop('disabled', false);
    } else { $('#cambio').prop('disabled', true); }
});
});

jQuery(document).ready(function($) {
    if($('#cambio').val() !== "") {
    $('#cambio').prop('disabled', false);
    } else { $('#cambio').prop('disabled', true); }
});
</code></pre>

<p>Note that there is some duplicated code. If you know how to slim down the code, every suggestion is welcome.</p>

<p>Thanks!</p>
