Javascript examples for DOM HTML Element:Form Event
Get only file name from file input, using substr and lastIndexOf()
<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>