SuperLes2006
01-18-2006, 10:28 AM
I'm trying to extract just the filename from a forms file upload field but just can't get it the way I want it.
Here's the code I'm using...
function extract(what)
{
if (what.indexOf('/') > -1)
answer = what.substring(what.lastIndexOf('/')+1,what.length);
else
answer = what.substring(what.lastIndexOf('\\')+1,what.length);
document.write(answer);
}
<form name="myform">
<input id="inpFile1" name="inpFile1" size="60" type="file">
<input style="height:23; color:#FF0000; font-weight:bold" type="button" value="Show Filename" onclick="extract(myform.inpFile1.value)">
</form>
Problem is that is writes the filename to a new white blank page in the top left corner.
How do I get it to write the filename to a spot on the current page? :confused:
Preferably right next to the Show Filename button.
alert(answer);
gives me a popup box with the filename but I don't want that.
Here's the code I'm using...
function extract(what)
{
if (what.indexOf('/') > -1)
answer = what.substring(what.lastIndexOf('/')+1,what.length);
else
answer = what.substring(what.lastIndexOf('\\')+1,what.length);
document.write(answer);
}
<form name="myform">
<input id="inpFile1" name="inpFile1" size="60" type="file">
<input style="height:23; color:#FF0000; font-weight:bold" type="button" value="Show Filename" onclick="extract(myform.inpFile1.value)">
</form>
Problem is that is writes the filename to a new white blank page in the top left corner.
How do I get it to write the filename to a spot on the current page? :confused:
Preferably right next to the Show Filename button.
alert(answer);
gives me a popup box with the filename but I don't want that.