I am uploading a file in Google chrome browser.
When I try to alert the value of the input file (abc.pdf) using the following code, it comes as C:\fakepath\abc.pdf
.
var ab = document.getElementById("myfile").value;
alert(ab);
So I tried the following methods to get the value of the file input....
- Used
split("\\")
mechanism, but it didn't get the result. - Tried to find out the last index of "\" by using
lastIndexOf("\\")
, But didn't find.
I have written the following code snippet. But can't understand how to proceed next.
Any suggestion will be highly appreciated.
<html>
<head>
<script type="text/javascript">
function show(){
var ab = document.getElementById("myfile").value;
alert(ab);
}
</script>
</head>
<body>
<form>
<input type="file" name="myfile" id="myfile" value="" onchange="show()"/>
<input type="button" name="submit" value="submit">
</form>
</body>
</html>