473,473 Members | 2,319 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamically added row shows as ‘undefined’ when accessing

1 New Member
am trying to dynamically add a row but when I try to access it it shows as undefined. With the ONLOAD event I call a function (addRow) to add a specific number of rows. These I can access fine. It is when I try to add the row from an ONCLICK event that I get the problem. See code snippets below...

Expand|Select|Wrap|Line Numbers
  1. function formatInit()
  2. {
  3.   for (var i = 0; i < 15; i++) 
  4.   {
  5.     addRow();
  6.   }
  7.   document.form.txtStoreNumber.focus();
  8. }
  9.  
  10. function addRow()
  11. {
  12.   rowCntr++;
  13.   //add a row to the rows collection and get a reference to newly added row
  14.   var newRow = document.all("tblGrid").insertRow(rowCntr);
  15.  
  16.   //add 7 cells (between <td></td>) to new row and set innerHTML to contain text boxes
  17.   var oCell = newRow.insertCell(0);
  18.   oCell.innerHTML = "<input type='text' name='txtAssocName' style='width: 155px'>";
  19.  
  20. //other 6 statement groups removed for readability
  21. }
  22.  
Expand|Select|Wrap|Line Numbers
  1. <body onload="formatInit();">
  2. ...
  3.         <table id="tblGrid"  width="800px" style="table-layout:fixed">
  4.           <tr align="center" border="1" bgcolor="#000000" style>
  5.  
  6.             <td width="160px"><font color="#FFFFFF">Associate's Name</font></td>
  7.             <!-- other 6 col headers lines removed for readability -->
  8.           </tr>
  9.         </table>
  10.         <br>
  11.         <hr>
  12.           <b>click on Add Row button to add more rows above...</b>   
  13.         <input type="button" value="Add Row" onclick="addRow();" />
  14.         <hr>
  15.  
Oct 11 '07 #1
1 1543
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

Can you add the rows when using onclick or do the rows not get added?

As a side note, instead of document.all, use document.getElementById(). document.getElementById is the standard method of accessing objects.
Oct 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
4
by: nick | last post by:
I have the following code to open a popup window and pass a value. In the main html page: var w = window.open("popup.htm","","width=510,height=450"); w.itemIndex = 100; // alert(w.itemIndex)...
4
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML...
2
by: Stephen Miller | last post by:
When I dynamically populate a HtmlSelect combo box, the Value property consistently fails to return the item selected, defaulting instead to the first item in the list. For example: Protected...
4
by: Jordan | last post by:
I need to dynamically add an ImageButton control to a user control and and do some server-side processing when the user clicks it. While I the ImageButton is added to the user control at runtime,...
5
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the...
3
by: keithb | last post by:
My code dynamically adds template fields to a GridView control. Everything seems to work OK, except when updating, because I haven't found a way to reference the dynamically added textboxes....
1
by: adamredwards | last post by:
I have a page with some form elements that are dynamically generated. They are inserted into the dom by first cloning a node, changing the values like name, and then inserted with insertBefore(). ...
7
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.