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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file upload and communication HTML to Javascript

Status
Not open for further replies.

davidinparis

Programmer
Jul 4, 2004
1
US
Good morning.

I am developing a Yahoo like e-mail processor and have a problem in selecting the names of attachment files. I want the processing of the files attached to be handled entirely withing Javascript.

I can open the Windows file select window using the following code:

<body>
<script language="javascript">
function browsefiles(elementname)
{
document.getElementById(elementname).click();
}
function filename(elementname)
{
// application code
}
</script>
<input type="button" id="myFile" value= "select" name="myFile" onclick="browsefiles('thefile');">
<input type="file" style='display:none;' id="thefile" value= "choose" name="fileselected" >
</body>

but can find no means of transmitting the file name and path back to the code in filename. Could someone assist?

This code does not seem to function in either Firefox or in Opera. Any suggestions.

Many thanks in advance.

David.
 
Any suggestions

The click method is not inherent in firefox (or opera either I'm guessing). Add this to your page to override the method and make it work for multiple browsers:
Code:
HTMLElement.prototype.click = function() {
   var evt = this.ownerDocument.createEvent('MouseEvents');
   evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
   this.dispatchEvent(evt);
};

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
uncle_rico_thumb.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top