aaakanks
aaakanks

Reputation: 43

getting error when I am using split method Uncaught ReferenceError: function is not defined

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

Answers (1)

Banzay
Banzay

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

Related Questions