Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q561 How can I extract just the file name from a forms file upload field?

You are here: irt.org | FAQ | JavaScript | Form | 6 | Q561 [ previous next ]

Try:

<script language="JavaScript"><!--
function extract(what) {
    if (what.indexOf('/') > -1)
        answer = what.substring(what.lastIndexOf('/')+1,what.length);
    else
        answer = what.substring(what.lastIndexOf('\\')+1,what.length);
    alert(answer);
}
//--></script>

<form name="myform">
<input type="file" name="myfile">
<input type="button" value="Test" onClick="extract(this.form.myfile.value)">
</form>

Feedback on 'Q561 How can I extract just the file name from a forms file upload field?'

©2018 Martin Webb