Get only file name from file input, using substr and lastIndexOf() - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Get only file name from file input, using substr and lastIndexOf()

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from  ww  w. j  a v  a2s .  co  m
var fullFileName = "C:\\Users\\****\\Desktop\\test.html";
var fileName = fullFileName.substr(fullFileName.lastIndexOf("\\")+1, fullFileName.length);
document.getElementById("log").innerHTML = fileName
    }

      </script> 
   </head> 
   <body> 
      <p id="log"></p>  
   </body>
</html>

Related Tutorials