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 all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

jQuery trigger on change or load

Options
  • 28-02-2014 9:28pm
    #1
    Registered Users 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 Posts: 1,263 ✭✭✭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