Calling a javascript function

Posted on 2006-06-08
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
    LVL 54

    Accepted Solution


    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

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    "I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now