In test() method:
var path="C:\test\hello.txt"; //returns -1 for path.lastIndexOf("\\").
why??
var pos=path.lastIndexOf("\\"); //return -1
But in showFile() method:
We are able to get the filename. The only difference is test()
hardcode the path,
but in showFile() we gets the path from the file dialog.
Please advise. thanks!!
<script type="text/javascript">
function test()
{ //var path="C:\\test\\hello.txt"; //good, it works
var path="C:\test\hello.txt"; //returns -1 for
path.lastIndexOf("\\"). why??
var pos=path.lastIndexOf("\\"); //unterminate string constant, use
"\\" for backslash
alert("pos=" + pos);
var filename = path.substring(pos+1);
alert(filename);
}
function showFile()
{ var path= InputForm.f1.value;
alert("path=" + path);
var pos=path.lastIndexOf("\\"); //unterminate string constant, use
"\\" for backslash
alert("pos=" + pos);
var filename = path.substring(pos+1);
InputForm.filename.value = filename;
}
</script>
<form name="InputForm" action="page2.asp" method="post">
<P><input type="button" name="b1" value="test file button"
onClick="test()">
<P>File Name: <input type="text" name="filename">
<P><input type="FILE" name="f1" onChange="showFile()">
</form>