• 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

attaching files through JavaScript

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , Please help me how to attach files like in Gmail-style using Javascript.

Thanks
indu
[ August 29, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use an iFrame to upload your files. Have you read the link that David O'Meara sent you for uploading files?
If using an iFrame, you should create one form per attachment, and every html-form should be submitted "within" an iframe. How?

... and so on. Once the servlet has uploaded your file, you'll see the response inside the iframe it was sent.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a separate forum for questions about HTML and JavaScript. I will move this topic to that forum; please follow the link at the top of this page to continue.
 
author
Posts: 85
5
PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YUI's Connection Manager (Ajax) abstracts a bit of hard work for you and makes your file upload code look like a normal Ajax request. It's using an iframe behind the scenes.

Or if you want to go fancy, flickr-style, you can use YUI's uploader control. The cool thing about it is that it let's the user upload multiple files in one selection (as in, you hold CTRL and select several files). It's using Flash. Later WordPress versions are using similar type of flash uploader.
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using this JS function to attach a file, as our team wants it to be without AJAX, then, in what way can I upload the files once they are attached?

function addFileInput()
{
var d = document.createElement("div");
var file = document.createElement("input");
file.setAttribute("type","file");
file.setAttribute("name","attachment"+upload_number);
d.appendChild(file);
document.getElementById("moreUploads").appendChild(d);
upload_number++;
}
thanks
indu
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without using Ajax or an iframe, you'll just need to do a normal form submission. You can;t get away without the server-side code to receive the file. JavaScript cannot upload the file on its own -- it can only initiate the client-side request.
 
Angel J Gama
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using iframes isn't ajax. It's just sending the form in another "window".
YOu could use the same JS function, but instead of append an input file within a div, you can so something like this:
It's probable that I've misspelled some js methods, but that's a way to do it (no ajax).
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot to All..
indu
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Angel J Gama:
Using iframes isn't ajax


Prior to XMLHttpRequest invisible iframes were used to make "backdoor" requests, and many consider that a form of Ajax. When it comes to file uploads, it's the only way to do it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic