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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:08:37+00:00 2026-06-09T03:08:37+00:00

I have a code which enabled the user to enter a Value in the

  • 0

I have a code which enabled the user to enter a Value in the first TextBox and I wanted it to populate the same value in the other TextFields with the same ID. (There are 9 Textfields in a column which have same ID)

Here is my code, but the problem is the value ONLY gets populated in the first inbox (TextF1) and nothing happens to the other 8. Does anyone see the issue here

<form >
<input type='text' id='VarField' onKeyUp="document.getElementById('VarField1').value=this.value"  value='' size="10">

<input type='text' name='TextF1' id='VarField1' value='' size="10">
<input type='text' name='TextF2' id='VarField1' value='' size="10">
<input type='text' name='TextF3' id='VarField1' value='' size="10">
.
.
.
<input type='text' name='TextF8' id='VarField1' value='' size="10">
<input type='text' name='TextF9' id='VarField1' value='' size="10">
</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-09T03:08:39+00:00Added an answer on June 9, 2026 at 3:08 am

    It’s bad practice to have more than one tag with the same ID – because of this, the getElementById method only accesses the first tag with that ID. Instead, give each input the same class, select all of them, and iterate through them.

    So your code would look something like this (I separated the function from the onKeyUp event to make it easier to see):

    <script type="text/javascript">
        function writeText()
        {
            var textFields = document.getElementsByClassName("VarField1");
            for(i = 0; i < textFields.length; i++)
            {
                textFields[i].value = document.getElementById("VarField").value;
            }
        }
    </script>
    
    <form >
        <input type='text' id='VarField' onKeyUp="writeText()"  value='' size="10">
    
        <input type='text' name='TextF1' class='VarField1' value='' size="10">
        <input type='text' name='TextF2' class='VarField1' value='' size="10">
        <input type='text' name='TextF3' class='VarField1' value='' size="10">
        <input type='text' name='TextF8' class='VarField1' value='' size="10">
        <input type='text' name='TextF9' class='VarField1' value='' size="10">
    </form>
    

    Note that you must iterate through in this way – although it’s tempting to use a foreach (for … in) loop, that will not work for the NodeList that getElementsByClassName returns.

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

Sidebar

Related Questions

I have a jquery code which enables a user to select amount of money
I have the following code which displays and enables a hidden field if 'Other'
I have code which needs to do something like this There is a list
So I have this code: $(document).ready(function() { $(document).keypress(function(e) { switch(e.which) { // user presses
I have some code, with which I'm trying to get the current session user
I have the following code, which is causing a leak, despite ARC being enabled
I have a WPF project which compiles just fine. However, when I enable code
I have code which has a drop down list. And when a certain option
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have code which as been working against an older Active Directory server and

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.