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 9007951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:49:34+00:00 2026-06-16T01:49:34+00:00

I have successfully created an HTML form that gets a file from a user

  • 0

I have successfully created an HTML form that gets a file from a user and also allows giving a name for the file. I have also succeeded in creating a javascript function that can get the name of the file from the upload stream, and only the name (without the path and extension). Problem is, I somewhat do not manage to change the input that’s there for renaming the upload like I want to. Here is the working function with two demonstrative alerts:

<script type="text/javascript">
function updateInput(val) {
    som = val.split('\\')[val.split('\\').length - 1];
    som = som.split('.')[0];
    alert('Hey 1');
    fileName.value = som;
    alert('Hey 2');
}; </script>

“Hey 1” alert is displayed and it’s alright.
“Hey 2” is actually not displayed!
fileName is both the name and id of the input for the file’s name, I DID try using document.getElementById(‘fileName’).value = … but with no luck.

Declaration of fileName:

<input type="text" runat="server" id="fileName" name="fileName" />

The javascript is located in the code under this input. The uploadImage input (which is type of file) is above this input. (Yes, the event is called and som gets the value I want it to have)

*I am trying to change the value of an input:text element. I will try the var thing.

THANK YOU IF YOU CAN HELP!

  • 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-16T01:49:36+00:00Added an answer on June 16, 2026 at 1:49 am

    As far as I understand your problem, code below should work fine:

    <script type="text/javascript">
    function updateInput(val) {
        var som = val.split('\\')[val.split('\\').length - 1];
        som = som.split('.')[0];
        alert('Hey 1');
        document.getElementById('<%=fileName.ClientID %>').value = som;
        alert('Hey 2');
    }; </script>
    

    Because of runat="server", id of an element in browser will be different from one you see in your .aspx file. Id of HTML element will be something like CotentPlaceholder1_fileName, so document.getElementById('fileName') will not find it and document.getElementById('fileName').value = son; will throw an error.

    The same problem with fileName.value = som; – as far as I understand, you are trying to use feature of IE (not sure if it is IE only feature, I just never use it but remember that there is something like that) which creates variables in global namespace using IDs of elements. ID is different from fileName, so variable name is different also.

    To get an id of an runat="server" element like it will be in browser, you can use .ClientID property of server side object.

    Also, you should use var to define a variable inside a function scope. Like var som = val.split('\\')[val.split('\\').length - 1];. This way it will not be visible in global scope (outside of updateInput function). Otherwise you may potentially get problems with it in future

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

Sidebar

Related Questions

I have successfully created an app that reads from a bundled .plist file and
I have successfully created a feature in sharepoint that modifies the existing edit dialog
I would like to have a custom snippet of html form code that takes
On form submission, it's telling me that it was successfully created but it's not
I have a registration form that when the user enters in valid registration data
I'm trying to use a list of clients that have been created from my
I have successfully created a custom Facebook open graph action, and have been able
i have successfully created distribution profiles and installed on my xcode organiser, but this
I have successfully created an application which is workable on the >3.0 devices. However,
I have created a REST web service and successfully used it with a client.

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.