How do I make jQuery code execute when a checkbox is checked programatically somewhere else?
<p>I have a HTML form with a dropdown box (<code>&lt;select id="state"&gt; ... &lt;/select&gt;</code> tag). I have a checkbox next to it (<code>&lt;input type="checkbox" id="not-from-US" /&gt;</code>).</p>

<p>The HTML dropdown item has a list of all United States stas (MO,TX,AL,etc.). But if the user is not from the United States, he/she checks the "Not from US" checkbox. Now in jQuery, I have programmed the checkbox (via <code>.change()</code>) to generate an additional field for selecting a country when the checkbox is checked. It also makes the dropdown select the "N/A" option.</p>

<p>I also programmed my form so that if the user selects "N/A" from the "States" dropdown menu, the "Not from US" checkbox gets checked. But how do I link the two events together? When the checkbox is programatically checked, the anonymous function for when the checkbox is checked does not fire.</p>

<p>How can I fix this?</p>

<p><strong>Edit:</strong> Sorry, I forgot to attach the sample code. Here it is:</p>

<pre><code>------------------index.php------------------

&lt;form action="index.php" method="post"&gt;
    &lt;select id="state"&gt;
       &lt;option value="None"&gt;None&lt;/option&gt;
       &lt;option selected="true" value="AL"&gt;AL&lt;/option&gt; 
       &lt;option value="AK"&gt;AK&lt;/option&gt; 
       &lt;option value="AZ"&gt;AZ&lt;/option&gt;
       &lt;!--etc.--&gt;
    &lt;/select&gt;
    &lt;input type="checkbox" id="not-from-usa" name="not-from-usa" /&gt;
&lt;/form&gt;

------------------main.js------------------

$(document).ready(function(){
    $('#state').change(function(){
        if ($(this).val() == "None") {
            $('#not-from-usa').attr('checked','checked');    // This is the important bit.
            // So now the #not-from-usa checkbox is checked. So the code below should execute, right?
        } else {
            $('#not-from-usa).removeAttr('checked');
        }
    });

    $('#not-from-usa').change(function(){
        if($(this).attr('checked')) {
            // Create an input element that the user can enter a country
            // Code omitted for clarity.

            // The code in here should execute once the checkbox is checked or unchecked.
            $('#state').val("None");    // Set the dropdown to the "None" selection
        } else {
            // Remove the extra input element that lets the user enter a country.
        }
    });
});
</code></pre>
