...

View Full Version : Auto fill Forms?



singedpiper
01-18-2006, 08: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?

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

mark87
01-18-2006, 08:22 PM
Sure,

<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.

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

head:



<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;
}

</script>



Form:



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

singedpiper
01-18-2006, 08:25 PM
whoops, crosspost, thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum