Solved

URGENT: How to check if file input field is empty

Posted on 2008-10-22
3
1,924 Views
Last Modified: 2010-08-05
Hi EE

I have written a code in html which asks the user to input a file. When the user submits the form I want to check whether the user has input the form. How can I do it?
The input command in HTML is
<INPUT TYPE=FILE id="Intfile" NAME="IntFile">

Thank you
0
Comment
Question by:tanpreetsingh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22779480
try:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title></title>
<script type="text/javascript">
function checkForm(f){
	if( f.IntFile.value=="" )
	{
		alert("You must select a file");
		return false;
	}
return true;
}
</script>
</head>
<body>
<form onsubmit="return checkForm(this)">
<INPUT TYPE='FILE' id="Intfile" NAME="IntFile">
<INPUT TYPE='submit' value="Submit" NAME="Submit">
</form>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:tanpreetsingh
ID: 31508876
Excellent solution. Thank you!
0
 

Author Comment

by:tanpreetsingh
ID: 22779634
Thank you. It worked smoothly.
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

635 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