Tim Jordan Posted August 12, 2020 Share Posted August 12, 2020 Hi everyone, I've been trying to look into getting a function to run whenever a page loads instead of having it happen on button click. To be more specific, I have an unordered list that I wanted sorted Alphabetically when it is loaded so there doesn't have to be a sort button on the top of the page. The page is an article inside of a main page and inside that article section is where the list is contained. I have tried the script from here: https://www.w3schools.com/howto/howto_js_sort_list.asp and it works when i have a button and click, but when I try to get it to run automatically it doesn't work. I have tried: just simply replacing the button line with <script>sortlist()</script> both above and below the list code using onload with inside the article element and ul elements to get it to execute Please let me know how this would be possible. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 12, 2020 Share Posted August 12, 2020 https://www.w3schools.com/code/tryit.asp?filename=GHOL2Q90GB81 Link to comment Share on other sites More sharing options...
Tim Jordan Posted August 12, 2020 Author Share Posted August 12, 2020 Thank you! not sure why that worked, but i pasted it below my list like you have it and now it works Link to comment Share on other sites More sharing options...
dsonesuk Posted August 12, 2020 Share Posted August 12, 2020 The page is read top to bottom, everything referred to must exist and be fully rendered. HTML with referred to id, class or possibly just tags such as ul, li. Defining of function with references, to class, id etc. Calling of function that must be defined before being called. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now