Solved

Problems with <input type="file">

Posted on 2003-11-14
14
3,270 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

777 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