?
Solved

how to simulate a button click on loading a page

Posted on 2004-11-21
5
Medium Priority
?
6,423 Views
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.

thanks

Julia
0
Comment
Question by:John Account
  • 2
  • 2
5 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 12641463
//something like this ?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function clickbtn()
{

document.getElementById('btn').click()
}
//-->
</SCRIPT>
</HEAD>

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

Expert Comment

by:sajuks
ID: 12641482
//another ex
<form action="http://search.google.com">
  <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].a.click();">
<input type=button value="simulate b click" onClick="document.forms[0].b.click();">
</form>
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12641483
I think only IE allows button .click()
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 1000 total points
ID: 12641517
I was wrong the above works in all browsers. This seems simpler

<body onload="document.f1.i1.click(); ">

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

0
 

Author Comment

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

Julia
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

850 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