473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

jQuery val() on input field only works when preceded by alert()

35
Hi,

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
  1. jQuery('input[type=file]').wrap('<div class="fileinputholder" style="position:relative;" />');
  2.             jQuery('input[type=file]').attr("style","position:absolute; z-index:2; opacity:0; filter:alpha(opacity: 0);");
  3.             jQuery('div.fileinputholder').each(function(){
  4.                 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" />');
  5.             });
  6.             jQuery('input[type=file]').each(function(){
  7.                 jQuery(this).change(function(){
  8. // UNCOMMENTING THE BELOW MAKES THE VAL() COMMAND WORK!                    
  9. //alert('changed');
  10. jQuery(this).next().val(jQuery(this).val());
  11.                 });
  12.             });
Any ideas? :)
Oct 20 '10 #1
0 1301

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Paul Jørstad | last post by:
Hello! In a form I have an input field. It's supposed to get input form a scanning device. Thus, the input might contain special characters (like the Group Separator in a EAN barcode). Now, I...
13
by: Eddie | last post by:
I need to validate a text input field. I just want to say if user enters 93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109 or 93110 or 93111 or 93116 or 93117 or 93118 or...
3
by: leiko | last post by:
I've written the following function who works great in IE function OnlyCharacter(tekst) { if (tekst.length == 1) { if (tekst >= "A" && tekst <="Z") {return true} } window.alert ("Only...
7
by: JW | last post by:
hello everybody I've got the following problem. I'm writing a form and I'm using javascript to validate fields (i.e. numeric, not blank). When my scripts detects an error I want it to put the...
5
by: Rune Runnestø | last post by:
How do I focus the cursor in the input field 'numberField' when accessing this jsp-file (or html-file) ? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head>...
13
by: Lee | last post by:
I have this function that doesn't work. I pass it the td element and an id, and it makes an input field inside the td. That part workds. What doesn't work is that I want to add an "onkeyup" on...
1
by: Winpygsfli | last post by:
I have an application that has an iFrame wich houses a form. I need to read the value of a specific input field from the iFrame. iFrame - portalArea Form - frmUserProfile Input field -...
4
by: mfaisalwarraich | last post by:
Hi everybody, I have some problem so need some help. wat im trying to do is making a function which will change the value of a input field when the value of other input field is changed. im using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.