Removable File Upload 1.0

Created Monday 27th of September 2010 by Andreas Lagerkvist
Copyright © 2010 Andreas Lagerkvist (andreaslagerkvist.com)

What it Does

This plug-in adds a "remove"-link next to input[type=file]:s that allows the user to remove a selected file from the input.

How to Use

jQuery('#file-uploader input[type=file]').removableFileUpload(); would make the input with type=file in the #file-uploader element removable.

Example

Example Code

HTML

<div id="jquery-removable-file-upload-example">
<
input type="file" name="foo"/>
</
div>

JS

$('#jquery-removable-file-upload-example input[type=file]').removableFileUpload();

Source Code

jQuery.fn.removableFileUpload = function (conf) {
    var 
config jQuery.extend({
        
remove:    'remove'
    
}, conf);

    return 
this.each(function () {
        var 
input        = $(this);
        var 
remove        = $('<span class="jquery-removable-file-upload"><strong></strong> [<a href="#">' config.remove '</a>]</span>').insertAfter(input).hide();
        var 
onchange    = function () {
            var 
file input.val();
                
file file.substring(file.lastIndexOf('\\') + 1);

            if (
file) {
                
remove.show().find('strong').text(file);
            }
            else {
                
remove.hide();
            }
        };

        
input.change(onchange);

        
remove.find('a').click(function () {
            
remove.hide();

            
input = $('<input type="file" name="' input.attr('name') + '"/>').replaceAll(input).change(onchange);

            return 
false;
        });
    });
};

Download

Plug-in

Requires

blog comments powered by Disqus

Random jQuery Plug-ins

  • Max Length Form Controls

    Gives form-controls with a 'maxlength-XXX'-class a max-length and prohibits user from entering more than set amount. It also displays number of charac...

    Details

  • Super Simple Tabs

    This is an extremely basic tabs-plugin which allows you to create tabbed content from the ever-so-common list of in-page-links. You can set the select...

    Details

  • Live Search

    Use this plug-in to turn a normal form-input in to a live ajax search widget. The plug-in displays any HTML you like in the results and the search-res...

    Details

More Plug-ins

Recent Comments

Powered by Disqus
Page cached. Loaded in: 0.0319 second(s).
Last DB change: 2012-04-02 11:06:05
Last file change: 2012-04-25 20:30:39
Cache created: 2012-05-17 22:09:39