Solved

URGENT: How to check if file input field is empty

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iframe - style elements within an iframe 7 36
Code Manager | Snippits 2 36
Selected in an option list 13 20
Get checkbox id of the previous one selected 2 15
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 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