how to simulate a button click on loading a page

Posted on 2004-11-21
Last Modified: 2008-01-09
Hi experts

I need a button to be programatically clicked when a page loads... how would I go about doing that?

I saw some things about a doClick function, but you'll have to talk to me like I'm 5 years old here.  I tried the doClick and it didn't work.


Question by:John Account
    LVL 33

    Expert Comment

    //something like this ?
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <SCRIPT LANGUAGE="JavaScript">
    function clickbtn()


    <BODY onload = "clickbtn()">
    <INPUT TYPE="text" NAME="txt">
    <INPUT TYPE="reset" id= "breset">
    <INPUT TYPE="button" id = "btn" value = "Click Me" onclick = "alert ('Hello World')">
    LVL 33

    Expert Comment

    //another ex
    <form action="">
      <input type="hidden" name="x" value="1">
      <input type="submit" name="a" value="a">
      <input type="submit" name="b" value="b">

    <input type=button value="simulate a click" onClick="document.forms[0];">
    <input type=button value="simulate b click" onClick="document.forms[0];">
    LVL 31

    Expert Comment

    I think only IE allows button .click()
    LVL 31

    Accepted Solution

    I was wrong the above works in all browsers. This seems simpler

    <body onload="; ">

    <form action="" name="f1">
       <input name="i1" type="button" value="simulate a click" onClick="alert('hi from the button')"> </p>


    Author Comment

    by:John Account
    Great GwynforWeb... that worked like a charm!


    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    755 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

    22 Experts available now in Live!

    Get 1:1 Help Now