• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to upload a file on the click of a button.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to upload a image file on the click of a Button.
Right now i m using a <html:file> to do the same, but it shows a
pair of "textbox" and "a Browse Button". But i dont want to show the textbox,
my requirement is only "Browse" Button, on click of that button a "File chooser" window should open, and after choosing file , it should be uploaded.

Please help me on this.javascript: x()
Frown
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this were my client demanding to do a file upload without a text box for the file, I would at least try to talk them out of it. I'd show them that on virtually every important site where one can upload a file, the control looks and acts the same. This is because the <input type="file" > control is a standard HTML control, and its appearance is pretty much under the control of the browser. The Struts <html:file> does nothing more than render a standard html <input type="file"> tag.

Only if the client turned deaf ears to the voice of reason would I then start researching ways to subvert the normal file upload process. I don't currently know a way to do this, but I'm sure there is some "black magic" one can do with JavaScript that might work. One thing that comes to mind would be to hide the actual <input type="file"> control by putting it in a <div> that is not displayed. You could then create a standard button that would trigger the file browse function.

Here is a good link that has a good explanation of how this control works and what can and can't be done to change it.

Since this really has nothing to do with Struts, I'm moving it out of the Struts forum and into the Html/Javascript forum.

Good luck!
 
reply
    Bookmark Topic Watch Topic
  • New Topic