Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:18:43+00:00 2026-06-01T23:18:43+00:00

I want to know how does the code below work to do because I

  • 0

I want to know how does the code below work to do because I have found this on a website for getting a file’s name but I don’t fully understand how it works:

function handleFileSelect(evt) {
    var files = evt.target.files;
    localStorage["fname"] = files[0].name; //save the name for future use
}

Is the code above correct for a form code like below:

  <form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return imageClickHandler(this);' class='imageuploadform' >
    <p><input name='fileImage' type='file' class='fileImage' /></p>
<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:18:46+00:00Added an answer on June 1, 2026 at 11:18 pm

    That function is bound is probably bound the to the change event of that file input field.

    So lets break this down.

    function handleFileSelect(evt) {
    

    When a function is bound as a listener to an event, typically an object that represents that event is passed in. This is the evt variable being accepted by this event handler function.

    var files = evt.target.files;
    

    For DOM events, event objects typically have a property called target that is a reference to the DOM element that triggered the event. So evt.target returns the file input element.

    And file input elements have a property called files, that is an array of file objects that the user has chosen (note that there may be only one file chosen, but it’s still going to be an array with only one item). That line assigns that array to the files local variable.

    localStorage["fname"] = files[0].name;
    

    localStorage is a persistent key value store (sorta like cookies) introduced as part of HTML5. "fname" is the key we are storing a value under. And files[0].name gets the first file object, and returns its name property, effectively getting the name of the selected file. This value is then stored, so that even if you refresh the page you can read back that last chosen filename just by running localStorage["fname"]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know if this is the correct website, but you guys have been
I am having a simple code where i want to know when does onRestoreInstanceState
I want to know what does RETURN_VALUE mean! I'm stuck at this thing. How
i have one domain link text i want to know that does google crawl
I have a generic method (see code below) and want to perform some action
How does async JMS work? I've below sample code: public class JmsAdapter implements MessageListener,
I have found some info on the subject ( like this link) , but
I know this does not sound Pythonic, but bear with me for a second.
Ok I am still having some issues with this code below. I have received
I want to know how does the SQL Server know what @p# is in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.