/ Published in: jQuery
URL: http://blog.vworld.at/2008/08/21/styling-an-input-typefile-using-jquery/
little enhancement of the jquery verion of this: http://www.quirksmode.org/dom/inputfile.html
Expand |
Embed | Plain Text
<input name="imgfile" id="imgfile" type="file" size="37" title="browser"/> <style> /* fakefileinput with jQuery */ div.fileinputs { position: relative; } div.fakefile { position: absolute; top: 0px; left: 0px; z-index: 1; } input.file { position: relative; text-align: right; height:28px; -moz-opacity:0 ; filter:alpha(opacity: 0); opacity: 0; z-index: 2; } </style> jQuery(document).ready(function() { $('input[type=file]').each(function(){ var uploadbuttonlabeltext = $(this).attr('title'); //get title attribut for languagesettings if(uploadbuttonlabeltext == ''){ var uploadbuttonlabeltext = 'Browse'; } var uploadbutton = '<input type="button" class="button_button" value="'+uploadbuttonlabeltext+'" />'; $(this).wrap('<div class="fileinputs"></div>'); $(this).addClass('file').css('opacity', 0); //set to invisible $(this).parent().append($('<div class="fakefile" />').append($('<input type="text" />').attr('id',$(this).attr('id')+'__fake')).append(uploadbutton)); $(this).bind('change', function() { $('#'+$(this).attr('id')+'__fake').val($(this).val());; }); $(this).bind('mouseout', function() { $('#'+$(this).attr('id')+'__fake').val($(this).val());; }); }); });
You need to login to post a comment.
