473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Dynamically Adding row and all value storre in variable

57
i add row dynamiccaly but value doesn't pprint. please help me.

My coding is as follow

Expand|Select|Wrap|Line Numbers
  1. <HTML>  
  2. <HEAD>  
  3.      <TITLE> Add/Remove dynamic rows in HTML table </TITLE>  
  4.      <SCRIPT language="javascript">  
  5.          function addRow(tableID) {  
  6.              var table = document.getElementById(tableID);  
  7.              var rowCount = table.rows.length;  
  8.              var row = table.insertRow(rowCount);  
  9.              var cell1 = row.insertCell(0);  
  10.              var element1 = document.createElement("input");  
  11.              element1.type = "checkbox";  
  12.              cell1.appendChild(element1);  
  13.  
  14.              var cell2 = row.insertCell(1);  
  15.              cell2.innerHTML = rowCount + 1;  
  16.  
  17.              var cell3 = row.insertCell(2);  
  18.              var element2 = document.createElement("input");  
  19.              element2.type = "text";  
  20.  
  21.              //element2.value =document.getElementById().value;
  22.              cell3.appendChild(element2);  
  23.         }  
  24.  
  25.          function deleteRow(tableID) {  
  26.              try {  
  27.              var table = document.getElementById(tableID);  
  28.              var rowCount = table.rows.length;  
  29.  
  30.              for(var i=0; i<rowCount; i++) {  
  31.                  var row = table.rows[i];  
  32.                  var chkbox = row.cells[0].childNodes[0];  
  33.  
  34.                  if(null != chkbox && true == chkbox.checked) {  
  35.                      table.deleteRow(i);  
  36.                      rowCount--;  
  37.                      i--;  
  38.                  }  
  39.              }  
  40.              }catch(e) {  
  41.                  alert(e);  
  42.              }  
  43.          }  
  44.      </SCRIPT>  
  45.  </HEAD>  
  46.  
  47.  <BODY>  
  48.      <INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />  
  49.      <INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />  
  50.  
  51.      <TABLE id="dataTable" width="350px" border="1">  
  52.          <TR>  
  53.              <TD><INPUT type="checkbox" name="chk"/></TD>  
  54.              <TD> 1 </TD>  
  55.              <TD> <INPUT type="text" /> </TD>  
  56.          </TR>  
  57.      </TABLE>  
  58.  </BODY>  
  59.  </HTML> 
Mar 3 '10 #1
1 2185
Logician
210 100+
What do you mean by "value doesn't print"?

If you want to copy the value of the previous field, where you have:

Expand|Select|Wrap|Line Numbers
  1. //element2.value =document.getElementById().value;
  2.  
Insert:
Expand|Select|Wrap|Line Numbers
  1. if( rowCount > 0 )  
  2.  element2.value = table.rows[ rowCount-1 ].cells[ 2 ].getElementsByTagName('input')[0].value;
  3.  
  4.  
Be careful about using childnodes, since some browsers include newline characters in the markup.
Mar 4 '10 #2

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

Similar topics

5
by: Lukelrc | last post by:
Hi, I have a dynamically created listbox. I'm trying to get one of the options selected according to a passed value. This is what i have: <select name="txtTheme" id="txtTheme"> ...
0
by: alex | last post by:
I'm new to xslt, and I am attempting to use it to produce a comma-separated-value file from a large, dynamically-generated data file formatted in xml (examples of the xml file and my xslt style...
10
by: David | last post by:
Can anyone give me a quick code snippet (that is standards-based) for adding OPTION tags to a SELECT dynamically. I have no problem doing it in IE but I am kind of new to the whole standards world...
20
by: David | last post by:
I have a one-line script to add an onunload event handler to the body of the document. The script is as follows: document.getElementsByTagName("BODY").onunload=function s() {alert("s")} Now...
3
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
7
by: cjl | last post by:
Hey all: I've searched the newsgroup, and googled, but I'm stuck. I want to be able to 'dynamically' add a .js file to a web page after the page has loaded, based on user interaction. For...
11
by: Daz | last post by:
Hello everyone. I am sure the answer to my question is simple, but I can't seem to dynamically add an onClick event to my script. I have a table which is generated dynamically, I am just...
7
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.