Solved

URGENT: How to check if file input field is empty

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now