select only image file validation in javascript




<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
function imageOnly(){
var file = $('#txtfile').val();
ext = file.substr(file.lastIndexOf('.')+1);
alert(ext);
if(ext=='jpg' || ext=='png' || ext=='gif' || ext=='bmp' || ext=='tif' ){}else { alert('Please select only Image'); $('#txtfile').focus(); return false ;}
}
</script>

<input type="file" name="txtfie" id="txtfile"  />  <input type="button" value="Upload File" onclick="return imageOnly();"  />

Comments

Popular posts from this blog

Call PHP Function In JavaScript Using Ajax

List of Post Category Wise in wordpress