Using jQuery and AJAX works for all functions except one, really bizarre issue (from my perspective)

Posted by CoreyT on Stack Overflow See other posts from Stack Overflow or by CoreyT
Published on 2010-04-29T16:32:19Z Indexed on 2010/04/29 18:37 UTC
Read the original article Hit count: 428

Filed under:
|
|
|
|

I am working on a classic asp form that has a number of dropdowns. Three of these are cascading, i.e. they rely in the previous dropdown. For almost everything this code works fine, one of them however is not playing nice.

To start off I have a script tag with the following in it:

    $(document).ready(function () {
        $("#AcademicLevel").change(getList);
        $("#CourseDeliveryTime").change(updateLocation);
        $("#ProgramType").change(updateEntryTerm);
    });

This works just fine for the first two elements of the form, AcademicLevel and CourseDeliveryTime, the third however does not take effect however. If I use Firebug's Console and run that same line of code, $("#ProgramType").change(updateEntryTerm);, it starts to work, sort of.

What happens is what confuses me. If the function it is pointing to, updateEntryTerm, has an alert() call in it, it works. If the alert is commented out, it does not work. The function is below:

    function updateEntryTerm() {
        $.ajax({
            type: "POST",
            url: "../Classic ASP and AJAX/jQueryExample.asp",
            dataType: "application/x-www-form-urlencoded",
            data: "Action=UpdateEntryTerm&acadLevel=" + $("#AcademicLevel").val() + "&courseTime=" + $("#CourseDeliveryTime").val() + "&programType=" + $("#ProgramType").val(),
            async: false,
            success: function (msg) {
                $("#EntryTerm").remove();
                $("#tdEntryTerm").append(msg);
                //alert(msg);
            } //,
            //error: function (xhr, option, err) {
            //    alert("XHR Status: " + xhr.statusText + ", Error - " + err);
            //}
        });
    }

I am lost on two different issues here, First why is the call to $("#ProgramType").change(updateEntryTerm); not working unless I run it in Firebug Console? Second, why does the function itself, updateEntryTerm, not work unless the alert() call is present?

Has anyone seem something like this before?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX