Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

JQuery not working

  • 22-11-2010 05:34PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 2,793 ✭✭✭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, Registered Users 2 Posts: 26,449 ✭✭✭✭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, Registered Users 2 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, Registered Users 2 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