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

  • Home
  • SEARCH
  • 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 8910523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:42:37+00:00 2026-06-15T03:42:37+00:00

So I have a page with a dynamically generate table that looks something like

  • 0

So I have a page with a dynamically generate table that looks something like

<table id="enProps">
  <tr>
    <td class="en_US">
      <input readonly="readonly" value="shipbillpayplacerequisition" type="text">
    </td> 
    <td class="en_US">
      <input class="longField" readonly="readonly" value="Ship, Bill &amp; Pay : Place Requisition" type="txt">
    </td>
    <td style="display: none;" class="otherIds">
      <input class="identifier" readonly="readonly" value="shipbillpayplacerequisition" type="text">
    </td> 
    <td class="keyValue">
      <input class="value longField" id="shipbillpayplacerequisition" value="" type="text">
    </td>
  </tr>
</table>

The number of rows can vary as can the what’s stored int eh value field of the input boxes. I’m trying to write a simple script in vanilla javascript (read: no external libraries such as JQuery) that compares the “value” values of two fields.

So far what I have is

 var table = document.getElementById("enProps");
 var rowCount = table.getElementsByTagName("TR").length;
 var engValue;
 var frenchValue;
 for (var i = 0; i < rowCount; i++){
  var row = table.rows[i];
  var cellCount = row.cells.length;
   for (var j = 0; j < cellCount; j++){
    var cell = row.cells[j];
     if (cell.getAttribute("class") == "en_US"){
       var inputs = cell.getElementsByClassName("longField")[0].getAttribute("value");
     }
   }
 }

Every time I try to run this get an error saying

cell.getElementsByClassName("longField")[0] is undefined

What’s odd is if I remove the getAttribute method call and print the value of inputs either with alert or console.log it shows the correct element. I’ve tried a number of variations including using .firstChild, .childNodes[0] and not stringing my method calls. Every single time I get an error saying either .getAttribute is not a function or that something is undefined and its always caused by the .getAttribute call on that line and what’s weirder is every single time calling console.log on my selector shows the appropriate input tag. So my question is why is .getAttribute erroring out when I trying to use it to get the value of the input tag’s “value” class?

  • 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-15T03:42:38+00:00Added an answer on June 15, 2026 at 3:42 am

    It’s because your first <td class="en_US"> doesn’t have a nested element with the class "longField".

    You would need to make sure a match is found.

     if (cell.getAttribute("class") == "en_US"){
         var inputs = cell.getElementsByClassName("longField");
         if (inputs.length)
             inputs[0].getAttribute("value");
     }
    

    Or just call getElementsByClassName from the tr instead.

    for (var i = 0; i < rowCount; i++){
        var inputs = table.rows[i].getElementsByClassName("longField");
        for (var j = 0, len = inputs.length; j < len; j++) {
            inputs[j].getAttribute("value");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that dynamically creates (using jQuery) Input boxes for the user.
The Scenario I have a table on a web page that is dynamically generated
So I have a page on which I dynamically generate a table and link
I have two different forms on one page that dynamically generate inputs. One is
I have a simple ASPX page that renders a dynamically generated HTML table to
I'm working on a web page where I have a dynamically generated table where
I have a trivia page that is dynamically generated by some javascript code. It
I have a page that has fields dynamically loaded via JQuery. It allows a
I have the following dynamically generated table on a page along with other tables
Have JSP page with dynamically generated HTML table with unknown number of rows. Have

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.