Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Auto fill Forms?

    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?

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    as a clarification, is it possible to run a function as soon as the file dialog has closed, rather than onblur?

  • #3
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    so, here's the script I have so far:

    head:
    Code:
    <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:
    Code:
    <input type="file" name="file" id="file" onchange="updateTitle();" />
    <input type="text" name="title" id="title" />
    Last edited by singedpiper; 01-18-2006 at 07:27 PM.

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    whoops, crosspost, thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •