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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

JQuery not working

  • 22-11-2010 5: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,584 ✭✭✭✭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