I've stumpled upon a very weird issue.
The situation is that I'm styling my own file input field, by replacing it with a text field and a button, lying below the original file input, which in turn has been given an opacity of 0. It looks great. However, when a file is selected I want to update my new "fake" text field with the file name.
This works, but only when the val() command is preceded by an alert!
Code:
Expand|Select|Wrap|Line Numbers
- jQuery('input[type=file]').wrap('<div class="fileinputholder" style="position:relative;" />');
- jQuery('input[type=file]').attr("style","position:absolute; z-index:2; opacity:0; filter:alpha(opacity: 0);");
- jQuery('div.fileinputholder').each(function(){
- jQuery(this).append('<input type="text" size="40" style="position:absolute;top:0px;left:0px;" /><img style="position:absolute; top:0px; left:270px;" src="images/browse.png" alt="browse" />');
- });
- jQuery('input[type=file]').each(function(){
- jQuery(this).change(function(){
- // UNCOMMENTING THE BELOW MAKES THE VAL() COMMAND WORK!
- //alert('changed');
- jQuery(this).next().val(jQuery(this).val());
- });
- });