Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JQuery not working

Options
  • 22-11-2010 6:34pm
    #1
    Registered Users Posts: 33


    I'm trying to get jquery to do something when the user changes a dropdown.

    $("#ddlDistrict").change(function() {
    alert("What's going on?");
    }

    When I run this in firebug, it shows the alert dialog.

    When I copy this to a .js file, nothing happens. :confused:
    The js file is linked to in the header.

    I thought this had something to do with document.ready, so I wrapped that around it, but no change. :(

    Any help appreciated.


Comments

  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    slap wrote: »
    I'm trying to get jquery to do something when the user changes a dropdown.

    $("#ddlDistrict").change(function() {
    alert("What's going on?");
    }

    When I run this in firebug, it shows the alert dialog.

    When I copy this to a .js file, nothing happens. :confused:
    The js file is linked to in the header.

    I thought this had something to do with document.ready, so I wrapped that around it, but no change. :(

    Any help appreciated.

    Are there any error messages when you move it to the JS file? If there aren't, try putting some dodgy syntax in there and seeing if there are when the page loads.

    The code should be within the document ready function so might as well keep it there. If you do get an error message when u put some dodgy code in, try passing the name of the HTML element ('ddDistrict') into the function in the JS file. Otherwise, there's something wrong with the way the JS file is being loaded.


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    ensure javascript is turned on in your browser.

    install firebug for your browser and ensure the jquery-x.x.x-min.js is actually found from your html page.

    firebug will tell you a whole load more


  • Registered Users Posts: 2,781 ✭✭✭amen


    really silly idea but have you added the jQuery include to your page?

    Have you navigated to your page (in a browser) right clicked and selected view source? Is your javascript there?


  • Registered Users Posts: 354 ✭✭AndrewMc


    Maybe just a copy-and-paste thing, but you're missing ");" at the end of the bit you quote.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    You can't set an event until the document is "ready"....inline Javascript might work, but having the code in an external JS file means that that code won't necessarily be loaded in time to run

    So wrap that code in a

    $(document).ready(function() {
    // INSERT YOUR CODE HERE
    });

    ....and you should be sorted.

    EDIT : Failing that, ensure that the jQuery JS file script is loaded BEFORE your own JS file.


  • Advertisement
Advertisement