Click to See Complete Forum and Search --> : .click() method behaves strange with <INPUT TYPE=FILE>


drcb
July 3rd, 2002, 07:32 AM
I'm trying to workaround style problem with "Browse" button in the <INPUT TYPE=FILE> (as far as I know - it is impossible to alter color, font and other style stuff of this button). So I invented to hide this fileupload control and make wrapper input control, which only calls methods from hidden fileupload.
Code is following:

<html>

<body>
<h>This is a test</h><br>
<form id="frm" method="POST" enctype="multipart/form-data">
This should be <input type="button" onclick="document.all.f.style.visibility='hidden';" value="Hidden"><br>
<input type=file name="f" style="visibility: visible;"><br>

This is for user:<br>
<input type="text" name="t" readonly=true style="border-color: green; font-color: red;">
<input type="button" name="b" value="BrowZe.." onclick="document.all.f.click(); document.all.t.value=document.all.f.value;" style="border-color: green;">

<br>
<a href="javascript:document.all.frm.submit();">Submit</a>


</form>
</body>
</html>

Now if I click native "Browse" button, select a file and then click "Submit" - all works as expected.
But if I click wrapper "Browse" button, select a file and then click "Submit" - I get "Access denied" exception.
Note: I'm not trying to write any data into file upload control, I'm only reading and calling its .click() method. And it works (shows file selection dialog, and correctly fills filename). But after this action browser goes into strange mode, when calling .submit() causes "Access denied" exception.
Is it MSIE's bug?
Is there workaround for this?

websmith99
September 27th, 2002, 06:28 PM
This is interesting. When I changed your Submit link to a
Submit button the form would submit.... after you pressed the
button TWICE.

drcb
September 30th, 2002, 02:49 AM
When using submit button it works only after second click. But sends an empty form :mad: .

vikasm123
October 14th, 2005, 04:51 AM
This code is working on IE,
but it is not working on mozilla,
please look into this.

PeejAvery
October 14th, 2005, 10:20 AM
When using submit button it works only after second click. But sends an empty form .
Could this be because you are getting the $_POST of the text instead of the file value???

The following code will work in IE only. I am looking into why it will not for Firefox. The submit button being clicked twice is just something that you have to deal with. It has to do with hiding a file input box. Extra mouse clicks are being processed.

<html>
<body>

<style>
.uploadbtn{
border-color: #00ff00;
}
.uploadtxt{
color: #ff0000;
border-color: #00ff00;
}
</style>

<form name="frm" method="post" action="file.php">
<input type="file" name="filename" style="display:none">
<br>
<input type="text" name="path" readonly="true" class="uploadtxt">
<input type="button" name="btn" value="BrowZe.." class="uploadbtn" onclick="frm.filename.click();frm.path.value=frm.filename.value">
<br>
<input type="submit" value="Submit">
</form>

</body>
</html>