Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  131] [ 1]  / answers: 1 / hits: 34968  / 14 Years ago, wed, january 19, 2011, 12:00:00

I have the following HTML code



<form action=/script/upload_key.py method=POST enctype=multipart/form-data> 
Key filename: <input name=file_1 type=file>
<input name=submit type=submit>
</form>


which gives me the following stuff.



alt



I was wondering




  1. How I can use JavaScript, to eliminate the need of Submit button. That's mean, once I Choose File, the selected file will be uploaded immediately?

  2. How can I make sure the field to display selected file name is long enough, so that ... will not be shown?


More From » html

 Answers
33

To submit it immediately, just do this:



<input name=file_1 type=file onchange=this.form.submit();>


If you are using JQuery:



$(input[name='file_1']).change(function() { this.form.submit(); });


About your other questions:



1) There are many methods out there... for example:



http://valums.com/ajax-upload/



http://www.webtoolkit.info/ajax-file-upload.html



(and many more. Just google for: Ajax file upload or iframe file upload)



2) Don't worry about the width of the field. As you don't know how long can it be the path, it would never be long enough (i think). Also browsers may display it very different. For example Safari or Chrome show it very different from Firefox or IE. Just use the default length or the one that looks better with your design.


[#94157] Monday, January 17, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devinjadong

Total Points: 711
Total Questions: 117
Total Answers: 100

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
devinjadong questions
Thu, Feb 17, 22, 00:00, 2 Years ago
Wed, Dec 8, 21, 00:00, 2 Years ago
Tue, Oct 27, 20, 00:00, 4 Years ago
Fri, Oct 18, 19, 00:00, 5 Years ago
;