C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Javascript »

Javascript Validation for uploading files...


Posted Date: 27 Jul 2009    Resource Type: Code Snippets    Category: Javascript
Author: satyaMember Level: Diamond    
Rating: 1 out of 5Points: 13 (Rs 8)




Description:



The below javascript funtion checks the browsing file. For example, If

the uploading file should accept only excel and word documents like that,

then in that scenario, we can use this function.



<script type="text/javascript">
function CheckFileExtension()
{
var ctrlUpload = document.getElementById('< %=FileUpload.ClientID% >');


//Does the user browse or select a file or not

if (ctrlUpload.value =='' )
{
alert("Select a file to upload!");
ctrlUpload.focus();
return false;
}


//Extension List for validation. Add your
required extension here with comma separator

var extensionList = new Array(".xls", ".doc");

//Get Selected file extension
var extension = ctrlUpload.value.slice(ctrlUpload.value.indexOf(".")).toLowerCase();


//Check file extension with your required extension list.

for (var i = 0; i < extensionList.length; i++)
{
if (extensionList[i] == extension)
return true;
}
alert("You can only upload below File Type:\n\n"+extensionList.join("\n"));
ctrlUpload.focus();
return false;
}



</script>


Attachments






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Javascript Validation for uploading files...  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Connect database using javascript
Previous Resource: Gridview Validations...
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use