Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

attaching files through JavaScript

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
 
Marshal
Posts: 67463
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks a lot to All..
indu
 
Bear Bibeault
Marshal
Posts: 67463
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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.
 
We can walk to school together. And we can both read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic