View Full Version : Auto fill Forms?

01-18-2006, 07:00 PM
I have a form that includes a file input and a text input. I'd like the text input to fill with the filename (sans path and extension) by default when the file input loses focus. What methods should I look into to learn to do this?

01-18-2006, 07:15 PM
as a clarification, is it possible to run a function as soon as the file dialog has closed, rather than onblur?

01-18-2006, 07:22 PM

<input type="file" id="filename" onchange="document.getElementById('textname').value=this.value" />
<input type="text" id="textname" />

If you wanted to remove the directories and extensions though you'd need to run the function to do that in the onchange event.

01-18-2006, 07:24 PM
so, here's the script I have so far:


<script language="javascript" type="text/javascript">

function updateTitle()
var filename = document.getElementById("file").value;
var namearray = filename.split('\\');
var basename = namearray[namearray.length - 1];
var namearray = basename.split('.');
var title = namearray[0];
document.getElementById('title').value = title;



<input type="file" name="file" id="file" onchange="updateTitle();" />
<input type="text" name="title" id="title" />

01-18-2006, 07:25 PM
whoops, crosspost, thanks

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum