I have a file field on a webpage in HTML like this:
<input name='a' id='a' type='file' />
On latest FF, Chrome and IE 11, also on Android 4.42 Chrome i can chec if person choose a file by doing:
document.getElementsByName('a')[0].value != ""
And it works properly.
But somehow on Android 2.3.7 native browser after i choose a file from a image gallery that was taken with a phone camera i see the name of the file in the file input selection field, but the script above returns false since value is empty.
So, how to properly check if a user selected a file in input file field in Android 2.3.7 native browser?
I add jQuery in case it has some proven solution.
Try this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input name='a' id='a' type='file' onchange="onFileChange(this)"/>
<script>
function onFileChange(file){
if(file.value){
alert('File is selected');
}
else{
alert('File is not selected');
}
}
</script>
</body>
</html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.