How to run this form .change() on load?
<p>I have created a script that dynamically updates the query based on filters (what user has chosen in the form) and loads the external php file with updated data, but I want to make the change function load when page is loaded.</p>

<p>The query is updated successfully when user changes any input and the external results are loaded. I want however to load the results when page is loaded and not wait for user input.</p>

<p>I have managed to make the form updates what the user has selected by storing cookies, still not sure how to make it load when he visits the page. I tried to add .trigger('change') at the end of $(".QueryElement").change(function() but I get inconsistent results, it does not work.</p>

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

<pre><code>&lt;script type="text/javascript"&gt;
$(function() {

    /*
    * Retrieve cookies in form
    */
    $("#showposts").val($.cookie('deluxe-' + 'numposts'));

    $(".tags, .categories, #show-all-tags, #show-all-cats").each(function() {
        if ($.cookie('deluxe-' + $(this).attr('id')) == 'checked') {
            $(this).attr('checked', true);
        }
        if ($.cookie('deluxe-' + $(this).attr('id')) == 'unchecked') {
            $(this).attr('checked', false);
        }
    });

    /*
    * This function is to add filters
    */
    $(".QueryElement").change(function() {

        var query = '';
        $.cookie('deluxe-form-state', 'activated', { path: '/', expires: 100 });

        query += "showposts=" + $("#showposts").val();
        $.cookie('deluxe-' + 'numposts', $("#showposts").val(), { path: '/', expires: 100 });

        function add_filters(showall, maincls, type) {
            if ($(showall).is(":checked") == false) {
            $.cookie('deluxe-' + $(showall).attr('id'), 'unchecked', { path: '/', expires: 100 });
            var val = [];
            $(maincls + ':checked').each(function(i){
            val[i] = $(this).attr('id');
            $.cookie('deluxe-' + $(this).attr('id'), 'checked', { path: '/', expires: 100 });
            });
            $(maincls + ':not(:checked)').each(function(i){
            $.cookie('deluxe-' + $(this).attr('id'), 'unchecked', { path: '/', expires: 100 });
            });
            query += "&amp;" + type + "=" + val;
            } else {
            $.cookie('deluxe-' + $(showall).attr('id'), 'checked', { path: '/', expires: 100 });
            $(maincls + ':checked').each(function(i){
            $.cookie('deluxe-' + $(this).attr('id'), 'checked', { path: '/', expires: 100 });
            });
            $(maincls + ':not(:checked)').each(function(i){
            $.cookie('deluxe-' + $(this).attr('id'), 'unchecked', { path: '/', expires: 100 });
            });
            query += "&amp;" + type + "=";
            }
        }

        add_filters('.show-all-cats', '.categories', 'cat');
        add_filters('.show-all-tags', '.tags', 'tag');

        $("#result").load('&lt;?php bloginfo('template_directory'); ?&gt;/GetResults.php?' + query);

    });

});
&lt;/script&gt;
</code></pre>

<p>And this is my queryform if you need it.</p>

<pre><code>&lt;?php

########################################
# showposts=
########################################

echo '&lt;select id="showposts" class="QueryElement"&gt;';
    for ($i = 5; $i &lt;= 50; $i += 5) {
        echo '&lt;option value="'.$i.'"&gt;'.$i.'&lt;/option&gt;';
    }
echo '&lt;/select&gt;';

########################################
# cat=
########################################

$categories = get_categories();
foreach($categories as $cat) {
    echo '&lt;input type="checkbox" name="'.$cat-&gt;cat_ID.'" id="'.$cat-&gt;cat_ID.'" class="categories QueryElement" /&gt; '.$cat-&gt;cat_name;
}
    echo '&lt;input type="checkbox" name="show-all-cats" id="show-all-cats" class="QueryElement show-all-cats" checked="checked"&gt; Include all categories';

########################################
# tag=
########################################

$tags = get_tags();
foreach($tags as $tag) {
    echo '&lt;input type="checkbox" name="'.$tag-&gt;slug.'" id="'.$tag-&gt;slug.'" class="tags QueryElement" /&gt; '.$tag-&gt;name;
}
    echo '&lt;input type="checkbox" name="show-all-tags" id="show-all-tags" class="QueryElement show-all-tags" checked="checked"&gt; Include all tags';

?&gt;
</code></pre>

<p>Edit: trigger at the end of function works but for first time load only, i get incosistent changes when the user updates the form when the page is loaded. The form is supposed to act as content filter, and the external file is supposted to act as content results filtered by the form.</p>
