Hello guys i am using a function to detect the image extension.
<body>
<input id="imgExtension" type="text" />
<input id="myFile" type="file" />
<script>
function checkExt(x){
var y = x.split('.').pop();
if (y != "jpg" && y != "png") {
return false;
}
else {
// i want to return *y*[image extension] from here
return true;
}
}
$(function(){
$("#myFile").change(function(){
var x = $(this).val;
if(checkExt(x)){
// i want to put [image extension] here in #imgExtension
$('#imgExtension').val();
}
else {
alert("Error, invalid image extension");
}
}
}
</script>
</body>
Recently, I was just checking the image extension and returning true or false but i want to get the extension as well because I need to parse it to my PHP script.
return {valid: true, extension : y}var x = $(this).val;should bevar x = $(this).val();