Solved

Problems with <input type="file">

Posted on 2003-11-14
14
3,267 Views
Last Modified: 2010-04-09
Hi everyone

I'm hoping that someone can help me out with this because its driving me crazy!

On my site i have a link that allows users to upload images.  When they click the link a java created pop up window is displayed which asks users to locate the file on thier computers through the use of <form> tags and a <input type="file" name="fileName"> input field.  Upon hitting the submit button, they user is taken to a page where my ASP script handles the file.  

The problem that im having is that for some reason everytime i hit submit with a value in the file input field (ie. someone has choosen a specific file to upload), the file field becomes blank the form won't submit to the next page.  Only when no value has been entered in the file field does the submit button actually work.

Now, i tried to simplify the code as much as possible so i don't think i've made a mistake because i've done procedures similar to this a few times at other places on the site.  I've also taken the code and called the file outside of the java pop-window and its worked fine.

Has anyone ever heard of an issue with <input type="file"> and java pop-ups?  Shouldn't i be able to do this?

Any suggestions or work arounds would be greatly appreciated.
Thanks in advance.
0
Comment
Question by:greeng
  • 7
  • 7
14 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 9747778
show us your form
0
 

Author Comment

by:greeng
ID: 9747815
Okay, this is the super simplified version.  Now, don't get me wrong, it works fine, just not in a pop up window.
Like, I can't make it any more basic then that.....


<html>
<head>
<title>Upload Company Logo</title>
</head>
<body>
  <form name="customLogo" method="POST" enctype="multipart/form-data" action="user_image_upload_submit.asp">
<input type="text" name="fileName" size="40">
<input type="submit" name="submit" value="Submit Your Image">
</form>
</body>
</html>
0
 

Author Comment

by:greeng
ID: 9747843
whoops...  this is what i ment to post (the input type is set to text.. i was just testing something out...)

 Comment from knightEknight
Date: 11/14/2003 06:09AM PST
 Comment    

show us your form

 
Comment from greeng
Date: 11/14/2003 06:13AM PST
 Your Comment  

Okay, this is the super simplified version.  Now, don't get me wrong, it works fine, just not in a pop up window.
Like, I can't make it any more basic then that.....


<html>
<head>
<title>Upload Company Logo</title>
</head>
<body>
  <form name="customLogo" method="POST" enctype="multipart/form-data" action="user_image_upload_submit.asp">
<input type="file" name="fileName" size="40">
<input type="submit" name="submit" value="Submit Your Image">
</form>
</body>
</html>  
 
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9748321
change the name of your submit button from "submit" to anything else like "Submit" or "btnSubmit"
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9748333
The form object has a method called "submit()" and if you name one of your form elements the same thing (as you did with your submit button) you over-write the submit() method.  So if you rename the button, the form can be submitted.
0
 

Author Comment

by:greeng
ID: 9748614
Thanks for your suggestions knightEKnight but no dice.  The form just simply erases what was entered in the file input field and does nothing.


... just in case....

<html>
<head>
<title>Upload Company Logo</title>
</head>
<body>
  <form name="customLogo" method="POST" enctype="multipart/form-data" action="user_image_upload_submit.asp">
<input type="file" name="fileName" size="40">
<input type="submit" name="btnSubmit" value="Submit Your Image">
</form>
</body>
</html>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9749014
all I did was change the action and it works for me:

<html>
<head>
<title>Upload Company Logo</title>
</head>
<body>
 <form name="customLogo" method="POST" enctype="multipart/form-data" action="javascript:alert(document.customLogo.fileName.value);">
  <input type="file" name="fileName" size="40">
  <input type="submit" name="btnSubmit" value="Submit Your Image">
 </form>
</body>
</html>

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:greeng
ID: 9749058
Thanks again KnightEKnight...

still having troubles though even when using a the simple java alert...
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9749187
hmm ... you mean if you cut-n-paste what I posted above and open it in a browser the alert doesn't show up?  What browser are you using -- and what version?
0
 

Author Comment

by:greeng
ID: 9749262
Yeah, i cut and pasted your code from above, reuploaded it to my server then tried opening a file.

What happends is that when a file is selected using the "Browse.." button it shows the path in the file input field, upon hitting submit all it does is clear the text box, like the action isn't even executed.  BUT if there is nothing in the path field, like if i simply open the file and hit submit without selecting any file with the "Browse.." button (or typing any text in the file input), i see the alert box displaying no message.

The browser i am using is IE 6.0
0
 

Author Comment

by:greeng
ID: 9749279
Also, this probelm is only happening with the "file" input type

If i select <input type="text" name="txtBox"> or whatever when I hit submit the value that i typed in appears in the java alert box without any troubles
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 230 total points
ID: 9749363
That is strange behavior.  I can't offer any thing more for now, sorry.
0
 

Author Comment

by:greeng
ID: 9749403
Yeah, I'll have to try to re-write stuff and see if i can get something to work

If any one has any more suggestions i'd really like to hear them


Thanks though KnightEKnight, points for effort my friend!
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9750927
thanks!  very generous of you  :)

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now