In test() method:
var path="C:\test\h ello.txt"; //returns -1 for path.lastIndexO f("\\").
why??
var pos=path.lastIn dexOf("\\"); //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\h ello.txt"; //returns -1 for
path.lastIndexO f("\\"). why??
var pos=path.lastIn dexOf("\\"); //unterminate string constant, use
"\\" for backslash
alert("pos=" + pos);
var filename = path.substring( pos+1);
alert(filename) ;
}
function showFile()
{ var path= InputForm.f1.va lue;
alert("path=" + path);
var pos=path.lastIn dexOf("\\"); //unterminate string constant, use
"\\" for backslash
alert("pos=" + pos);
var filename = path.substring( pos+1);
InputForm.filen ame.value = filename;
}
</script>
<form name="InputForm " action="page2.a sp" 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="showF ile()">
</form>