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
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.

jQuery trigger on change or load

  • 28-02-2014 09:28PM
    #1
    Registered Users, Registered Users 2 Posts: 67 ✭✭


    I'm using jQuery to check if a form element changes. Then on change I trigger ajax and load the results.

    However, when the user first lands on the page there will be no results as there has been no change to a form element.

    How do I write code which will trigger on change and when the page first loads?

    I thought the following would work. But only works on change.
    $('#form').on('change load', function(){
    
    //code goes here
    
    });
    
    

    I've been banging my head against the table trying to get this to work.


Comments

  • Registered Users, Registered Users 2 Posts: 1,267 ✭✭✭00sully


    use the ready event as per JQuery API http://api.jquery.com/ready/

    $( document ).ready(function() {
    // Handler for .ready() called.
    });

    this will tell you when the dom is ready. if you need everything on the page to be loaded - images, stylesheets etc... you window.addEventListener('load' function()...


Advertisement