[Javascript] Programmatically invoke the file browse dialog of input type=file

Gaz Newt newtquest at yahoo.co.uk
Fri Sep 29 15:26:59 CDT 2006


I want to have a separate button which invokes the "browse" button on an input type=file. In internet explorer the following code works ok, in firefox nothing happens.

All I do is call click() for the input control.

Do you know how to make this work in firefox?

Thanks


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <script type="text/javascript">
    function test()
    {
        var oTest = document.getElementById( "mytest");
        oTest.click();
    }
    </script>
</head>

<body>

<form id="myform" action="test.aspx" method="post">
    <input type="file" id="mytest" value="monkey" />
    <br />
    <input type="button" value="Programmatically Invoke The File Browser Dialog" onclick="javascript:test();" />
</form>
</body>

</html>

 		
---------------------------------
 The all-new Yahoo! Mail goes wherever you go - free your email address from your Internet provider.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20060929/73059be0/attachment.htm>


More information about the Javascript mailing list