Solved

URGENT: How to check if file input field is empty

Posted on 2008-10-22
3
1,918 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
  • 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

803 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