Solved

URGENT: How to check if file input field is empty

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

919 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

23 Experts available now in Live!

Get 1:1 Help Now