[thelist] JavaScript fun

Jim McNulty jkmcnulty at mediaone.net
Sat Apr 14 00:45:06 CDT 2001

First, I think Anthony is right and it should be done server side.  If you
must do it client side, then I think you want to make the filename field
into a "hidden" type instead of "text".  Then, on the "uploadfile" field,
put in an onChange event handler.  You'll need a little function which
parses the value of the uploadfile field and rewrites the value of the
hidden filename field.  This is a little rough, but it might be a good
starting point:

<SCRIPT type="text/javascript">
function getName()
   // parse the uploadfile value for the name
   myRegExp = /[^/\\]*\..*/gi;
   document.mainForm.filename.value =

<form name="mainForm" method="post" action="somescript.php">
<input type="file" name="uploadfile" onChange="getName();"> <br>
<input type="hidden" name="filename">

More information about the thelist mailing list