473,903 Members | 4,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with dynamic rows in table

14 New Member
Hello all,

I have a question and I'd be glad if any of you could help me :) I have written code to add rows dynamically to an existing table. When the user first comes to the page, there are 2 rows in the table already. If he so wishes, he can add additional rows. Whilst creating the rows, I have set the 'id' and 'onchange' attributes.

Now when he comes back to this page after going forward 1 page, the table is not loading with all values. Here's the problem. It only loads the first 2 rows, a.k.a, the rows which were present static in the table.

Any ideas on why is this happening, and how can I get the table to load all rows?

I have pasted relevant sections of my code below:

Expand|Select|Wrap|Line Numbers
  1. /* **** Code Start **** */
  2.  
  3. /* function to add rows to the table dynamically */
  4. function addRow(tableID) {  
  5.  
  6.  this.count++;
  7.  
  8.  var table = document.getElementById(tableID);
  9.  
  10.  var rowCount = table.rows.length;
  11.  
  12.  var row = table.insertRow(rowCount);
  13.  
  14.  var cell1 = row.insertCell(0);  
  15.  var element1 = document.createTextNode("Provider:");  
  16.  element1.type = "text";
  17.  cell1.appendChild(element1);
  18.  
  19.  var cell2 = row.insertCell(1);
  20.  var provID = document.createElement("select");
  21.  provID.setAttribute('id', ('document.circuits.providers' + (rowCount - 2)));
  22.  name = provID.setAttribute("onchange", 'provider(this);');
  23.  loadPopup (provID, Organisations, "a Circuit Provider");  //funciton to populate the select element
  24. cell2.appendChild(provID);
  25.  
  26. alert("the id is: " + provID.id); //correctly prints document.circuits.providers1 
  27. alert("provID: " + provID); // correctly prints HTMLSelectElement
  28. }
  29.  
  30. /* function to load the page on entry */
  31. function loadPage ()
  32.      {
  33.  
  34.  
  35.      var t = "";
  36.  
  37. // it comes to this part when user comes back to this page
  38. if ((top.providers).length > 0) {
  39.  
  40.          for (i = 0; i < (top.providers).length; i++) {
  41.              var y = 'document.circuits.providers' + i;
  42.              alert("y is: " + y);
  43.              t = eval('document.circuits.providers' + i); // works with only 0
  44.              alert("now t is: " + t);  //'t' prints as 'undefined'
  45.             top.providerNames[i] = top.LoadPopup (t, Organisations, "a Circuit Provider", top.providers[i]);
  46.          }
  47.      }
  48.      else { // comes to this part when user first comes to this page
  49.  
  50.          // provide for one circuit provider info to be entered - user can add more if he needs
  51.  
  52.            top.allProviderIDs = "";
  53.              top.allProviderNames = "";
  54.  
  55.              t = eval('document.circuits.providers' + 0);
  56.              alert("t is: " + t);             
  57.              top.providerNames[0] = top.LoadPopup (t, Organisations, "a Circuit Provider", top.providers[0]);        
  58.  
  59.      }
  60. }
  61.  
  62. <body onload="loadPage();">
  63.  
  64. <div id="mainbody">
  65.  
  66. <form>
  67. <table>
  68. <!-- etc etc -->
  69. </table>
  70. </form>
  71. </div>
  72. </body>
  73. </html>
  74.  
  75. /* **** Code End **** */
  76.  
There's no syntactical error so I know the code is fine. Just the id on revisiting the page is messed up. Please help, I'd really appreciate it.

Thanks!
- Trupti
Sep 1 '09 #1
5 2576
Markus
6,050 Recognized Expert Expert
Do you mean that when a user is using the back button in the web-browser, the original 2 rows are being shown? If so, that's because the browser is caching what is first loaded by the browser, i.e. those 2 rows. What you add after the page load, dynamically, is not cached.

You could overcome this by setting a cookie that stores information such as the amount of rows and the data stored by the rows. There may be a more elegant solution to this, though.

Mark.
Sep 1 '09 #2
truptivk
14 New Member
Hello Mark,

Thanks for your reply. No I don't mean the browser's back button. I have buttons on my page to move back and forward.

- Trupti
Sep 1 '09 #3
gits
5,390 Recognized Expert Moderator Expert
but is that an entire page-reload during the operations? JavaScript-variables don't persist after unloading a page ... but you might pass the values from page to page
Sep 1 '09 #4
truptivk
14 New Member
Gits,

Yes it is a reload of values chosen the first time around. I have a way of passing the values from page to page; whats missing is how to get to display the values previously chosen in the dynamically added rows. And yes, when I come back to the page, I have the values. I just need a way of displaying them.

When adding rows dynamically for the first time, if you see the code, I have used setAttribute to set the id to 'document.circu its.providers' + (rowCount-2) - which will be document.circui ts.providers1, document.circui ts.providers2 etc. document.circui ts.providers0 is the static row, which is set in loadPage().

Problem is - when I come back to same page, I need to reconstruct the table. I can show the row with id document.circui ts.providers0, but not dynamically added ones like document.circui ts.providers1, document.circui ts.providers2 etc. Once again, to avoid confusion, I would like to say that I have the values that need to be shown in document.circui ts.providers1, document.circui ts.providers2 etc. Building the table with the id is proving a hurdle.

Hope I'm clear :) Thanks for all your patience.

- Trupti
Sep 1 '09 #5
gits
5,390 Recognized Expert Moderator Expert
i just guess that you add the rows with the addRow() method of your posted code? ... so basicly you would need to call that method and add the corresponding values to the created cells? it seems that you loop already through the data in question ... so just pass the values to the function and add it during the creation/add-process in addRow()

aah ... and where does the tableID come from?
Sep 2 '09 #6

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

Similar topics

18
5996
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query against a different table (that uses the LIKE predicate) but cannot get around the SQL0132 error . I have tried the hex notation after the LIKE such as (without the quotes)... " where colNewPartNum like ( X'27' || nnn.colPartNum || X'27) " ,...
4
2287
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5 companies on a form. 3 of the companies have common employees. I have a table that looks like this:
6
2660
by: hb | last post by:
Hi, I have a page bill.aspx and its code-behind bill.aspx.cs. On bill.aspx I have: === Select a month: <asp:dropdownlist runat="server" id="lstDate" autopostback="True" /> <br> <asp:table runat="server" id="tabBill" /> <br>
1
3358
by: Henke | last post by:
Hello, I have one ImageButton controls which I initialize in Page_Load and declare on class level. ImageButton save = new ImageButton(); save.ImageUrl = "save.gif" save.Click += new ImageClickEventHandler(this.save_click); This ImageButton is added to a dynamic table which is also
15
2589
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
1
7545
by: peaceburn | last post by:
Hi, I'm gonna pull my hair in the coming days with these DB2 stored procedures. So the issue, let's assume a simple stored procedure like this : CREATE PROCEDURE MYSCHEMA.PROCEDURE1 ( ) DYNAMIC RESULT SETS 1 ------------------------------------------------------------------------
9
5325
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from http://blogs.crankygoblin.com/blogs/geoff.appleby/pages/50712.aspx. I've also read the post on this topic by bggraphics, but he doesn't arrive at a final result. The main problem I am having is that the layerX and layerY event properties don't work. They're supposed to return the...
4
1743
by: SirCodesALot | last post by:
Hi All, I am trying to dynamically replace a table in the dom, anyone have an idea on how to do this. here is some sample suedo code of what I want to do. var tableHTML = "<table id=\"table1\"><tr><td>this is table 1</td></ tr></table>"; var tableHTML2 = "<table id=\"table2\"><tr><td>this is table 2</td></
12
24833
by: ive1122 | last post by:
Hi guys, I am looking into create a dynamic survey as posted in Get User Input From Dynamic Controls but with some different environment Below is what i am trying to do: First when the user click the button, it will populate a dynamic table with radio button for the survey questionnaire However, i was unable to get its value (for score calculation) after clicking the submit button Beside i am using an ajax extension (updatePanel) for the...
0
9847
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10875
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10986
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8049
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5894
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6093
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4727
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 we have to send another system
2
4308
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.