Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Form 6 | Q561 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.