devxlogo

Calling a Script Function Without User Input

Calling a Script Function Without User Input

The most common way to call a script function is to have an element trap an event, which in turn calls the function, as in:

 
Click here

But what if you want a function to perform a task as soon as the page loads without any user input? In that case, you can use the onload event, placing it in the Body element of your page, as in:

  

The function will be called immediately after the page loads, and no user input is required.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist