Reputation: 43
Using split method I want to break url and want only image name in input fild after selecting file from folder. but it showing whole path c:\fackpath\xyz.png
<html>
<head>
<script type="text/javascript">
function alertFilename()
{
var thefile = document.getElementById('thefile').value;
var x = thefile.toString()
var y = x.split("\")[0];
var y = document.getElementById('x').value = thefile;
}
</script>
</head>
<body>
<form>
<input type="file" style ="width:90px" id="thefile" onchange="alertFilename()" />
<input type="text" id ="x" value="" />
<p id ="demo"></p>
</form>
</body>
here is I attache plunker link
Upvotes: 0
Views: 2437
Reputation: 9470
I think you just need to write double backslash for right split, because backslash is a special char.
var y = x.split("\\")[0];
Upvotes: 1