Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

click link fire a button 1

Status
Not open for further replies.

codeone

Programmer
Mar 25, 2003
343
US
hey,

wondering how to set up a link that when clicked would fire a button as if I actually clicked the button.

fanatsy example:

Code:
 . . .
<script>
function openIt()
{
document.alpha.fileBttn.click;  //call to click browse button
}
</script>
</head>

<body>
<form name="alpha">
<a href="#" onclick="openIt()">Open</a>  <!--calls openIt()-->
<input type="file" name="fileBttn">  <!--link fires this-->
</form>
 . . .

This doesn't work obviously but is a good example of what I'm trying to do, assuming you understand this is not a functioning script and meant only to serve as an example.

regards

co
 
Sure (and it's a nice way to customise the file upload button too). You need to just give the button focus.

Code:
document.alpha.fileBttn.focus();

That should do the same as clicking the button I believe.

Jeff
 
No that didnt work...however this script does:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">

<html>
<head>
	<title></title>
    <script>
    function openIt()
    {
    document.script.fileBttn.click();
    }
    </script>
</head>

<body>
<form name="script">
<input name="fileBttn" type="file">
<a href="#" onclick="openIt()">Open</a>
</form>

</body>
</html>

Looks like my fantasy example was dang near reality...

I'm giving this post a star because if you hadn't posted that code I would have never thought to add the '()' and that was the thing I needed.

so thanks,

co
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top