?
Solved

Javascript access to file field

Posted on 2007-10-09
4
Medium Priority
?
632 Views
Last Modified: 2008-01-09
Hi,
I have a file field:

<form id="frmFile1" name="fileForm1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="file1">
<form>


using javascript, how can I check if a file has been entered in the file field?
0
Comment
Question by:burnsj2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 20042923
Though IE supports using ActiveX, it is not at all browser compatible due to security reasons. You should be using other technologies like java/jsp or asp
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 20043111
capture the onchange event

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="frmFile1" name="fileForm1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="file1" onchange="alert(this.value)">
<form>
</body>
</html>
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 2000 total points
ID: 20043149
You can check for a value with Javascript with ...

if (document.fileForm1.file1.value != '')

You should have the id and name in the form tag the same.  The id of course needs to be unique.  If the Javascript doesn't work then the different name and id in the form tag maybe the issue.

If you really want to check the value then it is best to still use server script, as mentioned above, but Javascript can do a quick check for a value being entered.

Let me know if you have a question or need more info.

bol
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20044883
Thanks for the grade, the points and the fun question.  I'm glad I could help.

bol
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 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