Does anyone know if i can write a generic javascript function that check the file extension
of the uploaded files and if the extension is incorrect erases the value
because the user upload's more then one file i want to get the ID from the form
something like:

   var fileEXT = obj.substring(obj.indexOf('.')+1, obj.length);
		if (fileEXT.toUpperCase() != 'XLS'){
			alert('Please Select Only XLS File');
                        /* erasing the file input text geting the name from "obj" */
                        /* something like document.getelemntbyname( = "";*/
<input type="file" name="firstXLS" onchange="fileselectedchange(this);" />

sorry if my english is not the best
thank you

'value' property is read-only. But there a work around you can use:

		function fileselectedchange(obj)
			var fName = obj.value;
			var fileEXT = fName.substring(fName.indexOf('.') + 1, fName.length);
			if (fileEXT.toUpperCase() != 'XLS'){
				// Reset the innerHTML with the initial one 
				document.getElementById('input1').innerHTML = divInnerHTML;
				return false;
		<div id="input1">
			<input id="fileInput" type="file" name="firstXLS" onchange="fileselectedchange(this);"/>
			// Store the initial innerHTML for the div.  
			var divInnerHTML = document.getElementById('input1').innerHTML;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.