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 trigger on change or load

  • 28-02-2014 08: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