Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2013, 01:32 PM   PM User | #1
docock
Regular Coder

 
Join Date: Feb 2007
Posts: 197
Thanks: 21
Thanked 1 Time in 1 Post
docock is an unknown quantity at this point
Jquery, Auto submitting a file after selection?

I've changed my 'file upload' input field into a hyperlink, which looks much better.
I also added an auto submit, so that when the file is picked it gets automaticly submitted (normally you first select the file, and then have to hit the submit button).

Everything works perfectly, except for the auto submit, which doesn't seem to function in Internet Explorer.
How can I make this coding work in every browser?

Code:
 <style type="text/css">
 #file {
    display:none;
 }
 
 .new_Btn {
 color:blue;
 cursor:pointer;
 }
</style>

 
 <script type="text/javascript" 

                     src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script type="text/javascript"> 


$(function () {

$('.new_Btn').bind("click" , function () {
        $('#file').click();
    });

$('#file').change(function() {
  $('#target').submit();
});

$('.new_Btn').change(function() {
  $('#target').submit();
});

});  
</script>

<html>
<body>

<form id='target' action='http://www.test.com' method='post' enctype='multipart/form-data'>
<div class='new_Btn'>Select file</div><br>
<input type='file' name='file' id='file'><br>
</form>

</body>
</html>
Ps: It works fine in Firefox, Chrome etc. but not in IE 8.0 (which is used by a lot of XP users).

Last edited by docock; 03-19-2013 at 04:42 PM..
docock is offline   Reply With Quote
Old 03-20-2013, 07:24 AM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
If you want, you can try this jQuery File Upload plugin.

https://github.com/blueimp/jQuery-File-Upload
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 03-20-2013, 07:28 AM   PM User | #3
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Or this:

http://stackoverflow.com/questions/2...put-file-on-ie
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:12 AM.


Advertisement
Log in to turn off these ads.