Started to fix a bunch of usability problems on the file and image
[cocanwiki.git] / html / _js / upload.js
1 /* $Id: upload.js,v 1.1 2004/11/01 16:05:27 rich Exp $ */
2
3 function set_name ()
4 {
5   if (document.f.name.value == "") {
6     var pathname = document.f.file.value;
7     /* Try to get just the filename.  Seems thereis no platform
8      * independent way to do it, so we will just guess.
9      */
10     var i = pathname.lastIndexOf ("/");
11     var j = pathname.lastIndexOf ("\\");
12     i = i > j ? i : j;
13     var filename =
14       i > -1 ? pathname.substring (i+1, pathname.length) : pathname;
15     filename = filename.toLowerCase ();
16     filename = filename.replace (/[^-a-z0-9_.]/g, '_');
17     document.f.name.value = filename;
18     return true;
19   }
20   return false;
21 }