javascript implements the validation file upload control instance


The example of this article describes the implementation of javascript validation file upload control. Share with you for your reference. The details are as follows:

The javascript validation file upload control code detects whether the type of the uploaded file is an image

<script language="javascript">
function Checkfiles()
{
var fup = document.getElementById('logo1');
var fileName = fup.value;
var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "png" || ext == "PNG")
{
return true;
}
else
{
alert("Upload JPG, JPEG, PNG, GIF images only");
fup.focus();
return false;
}
}
</script>
onchange="Checkfiles()"

I hope this article is helpful for you to design javascript program.