Reputation: 11
<script>
function attachFile(){
document.getElementById("file").click();
return;
}
</script>
<form name="novsh" style="margin: 0px; padding: 0px;">
<input type="file" name="file" style="display:none" id="file" />
</form>
<a href="javascript:attachFile()">Attach File</a>
<input type="button" name="btn" value="click me" onclick="attachFile()"/>
I've written like this and it's working on IE but not working on FireFox
Upvotes: 1
Views: 2739
Reputation: 11238
Firefox does not allow you to programatically call click()
on a file input.
Upvotes: 1
Reputation: 10961
The click()
function on elements that aren't form inputs is a non-standard feature that only exists in IE.
If you're trying to call the element's onclick
handler, you can do this:
document.getElementById("file").onclick();
Edit:
Turns out this is a form input, so...never mind.
But it looks like what you're trying to do is get the file picker dialog to pop up. I'm not aware of any programmatic way to do that. I would agree with RoToRa's comment that such a capability is probably a security flaw.
If your ultimate goal is to create a file input element that can be styled differently from the browser's defaults, check out this article.
Upvotes: 4