Calling a javascript function

Posted on 2006-06-08
Medium Priority
Last Modified: 2010-05-18

How would I call a javascript function WITHOUT clicking a button. I have seen several examples where the function concerned
is called by onClick, by attaching to a button. I do not need that. In my case, my program checks for a condition and if a certain
condition is not satisfied, I want to popup a message. How would I do this?

Question by:prain
  • 2
LVL 54

Accepted Solution

b0lsc0tt earned 300 total points
ID: 16864191

I feel the most common way would be to use the onLoad attribute of the body tag.  Reference a JavaScript function that you have placed in the head section of the page.  This is the method I would suggest with the details you provided.

An example of a body tag with the attribute I mentioned is below:

<body onload="testpage()">

The onload could contain the code itself or reference a function (my example used testpage) that you placed in the head section or even in the body.  Let me know if you need more information or have a question.

LVL 54

Expert Comment

ID: 16865197
I'm glad that I could help.  Thanks for the grade, the points and the fun question.


Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question