Jump to content

upload file

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
leeyo

leeyo

    Newbie

  • Members
  • PipPip
  • 12 posts
<input id="file" name="file_upload" type="file" style="display:none">
<a id="open_upload" href="#">upload file</a>

I want to open the <input type="file"> when I click "upload file".
any ideas?

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
This should work, plug the onLoad into your <body> tag and the rest should work:
<body onLoad="document.getElementById('filebox').style.visibility = 'hidden';">
<a id="open_upload" href="#" onClick="document.getElementById('filebox').style.visibility =  'visible';">upload file</a>

<input type="file" id="filebox">

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
leeyo

leeyo

    Newbie

  • Members
  • PipPip
  • 12 posts
no.I don't want this.
I mean when click "upload file",and the file chosen dialog is open.don't need to click <input type="file">.

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
I think you mean you want to click on <a id="open_upload" href="#">upload file</a> and then the browse window opens, but the input type="file" remains hidden?

In that case it's only possible in IE doing something like:
<head>
<style type="text/css">
.opaque {
    visibility:hidden;
}
</style>

<script type="text/javascript">
    function browse(){
        var browse = document.getElementById('filebox');
        browse.click();    
    }    
</script>
</head>
<body">

    <a id="open_upload" href="#" onClick="browse();">upload file</a>
    <input type="file" id="filebox" class="opaque">

</body>
Only IE supports the .click( )

Why not just remove the <a id="open_upload" href="#">upload file</a> and use the input type="file" only then?

#5
leeyo

leeyo

    Newbie

  • Members
  • PipPip
  • 12 posts
Thanks oxano.
That's easy.thank you very much.
I saw this method in qq.com,it's different from i have ever seen.and it is specially and good looking.