I have some code that when a user selects an item from the dropdown, this triggers a change event which then calls a php page for processing. When the page first loads, I select an item and when the change event is triggered, this should change the placeholder of a chosen select input and disable the same input: '#box_ffrtv'.
However, what is happening is that the changes only take place after I make a second selection the in the dropdown, this then changes the placeholder and disables the input. I am still quite new to jquery and would appreciate some help as to where I am going wrong. Many thanks.
jQuery 1.7.2:
jQuery chosen: http://harvesthq.github.io/chosen/
jquery code
$(function() {
        $("#frtv_dept").change(function() {
            $(this).after('<div id="loader"><imgages src="img/loading.gif" alt="loading files" /></div>');
            $.get('loadFrtvsubcat.php?frtv_dept=' + $(this).val(), function(data) {
                $("#box_frtv").html(data);
                $('#loader').slideUp(200, function() {
                $(this).remove();
                $("#box_frtv").trigger("chosen:updated");
            });
        });
    });
});
php code
if (mysql_num_rows($result) > 0) {
    echo "<script type=text/javascript>\n";
    echo "$(function() {\n";
    echo "$(\".noRtvBoxes\").html('')\n";
    echo "$('#box_frtv').attr('data-placeholder', \"Choose your boxes...\")\n";
    echo "$(\"#box_frtv\").prop('disabled', false)\n";
    echo "});\n";
    echo "</script>\n";
    while($row = mysql_fetch_array($result)) {
    echo "<option value='$row[boxref]'>$row[boxref]</option>";
    }    
    } else {
    echo "<script type=text/javascript>\n";
    echo "$(function() {\n";
    echo "$('.noRtvBoxes').html('ERROR: There are no boxes in that dept. Please select another.').css({\"color\":\"red\", \"margin\": \"-6px 0 10px 22px\", \"font-size\": \"12px\", \"font-family\": \"Verdana, Geneva, sans-serif\"})\n";
    echo "$('#box_frtv').attr('data-placeholder', \"No boxes to display...\").prop('disabled', true)\n";
    echo "$('#box_ffrtv_chosen').find('option:selected').remove()\n";
    echo "$('#box_ffrtv').html('')\n";
    echo "$('#box_ffrtv').trigger(\"chosen:updated\")\n";
    echo "$('#box_ffrtv').attr('data-placeholder', \"No files to display...\")\n";
    echo "$('#box_ffrtv').prop('disabled',true)\n";
    echo "$('.noRtvFiles').html('ERROR: There are no files in that box. Please select another.').css({\"color\":\"red\", \"margin\": \"-6px 0 10px 22px\", \"font-size\": \"12px\", \"font-family\": \"Verdana, Geneva, sans-serif\"})\n";
    echo "</script>\n";
    }
html code
<select data-placeholder="Choose your file(s)..." class="chosen-select" name="box_ffrtv[]" id="box_ffrtv" multiple required="required">
   <option value=""></option>
 </select>
 
     
    