[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

How to add form elements after insertRow?

Asked by IT79637 in Document Object Model, JavaScript

Tags: DOM javascript

I am experimenting with adding and removing rows from the end of a table dynamically. It is actually more than experimenting it is a project to add to my resume and need to get it done so I can hit the pavement!!!

Here is how I am writing the javascript to dynamically add or remove table rows.

1. Get the number of rows and do an insertRow:

  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  //if theres no header row in the table, then iteration = lastRow + 1 *l
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);

Can I assign a css class to the row? If so, how?
For example:
.blck11 {
      font-family: Arial, Helvetica, sans-serif;
      font-size: 11px;
      font-style: normal;
      font-weight: normal;
      color: #000000;
      text-decoration: none;
}

2. Do an insertCell(0,1,2,3,4,etc...) for number of cells in table. I am inserting three
types of html into the cells:

A. CSS - set background color to the cell.

B. Input Box - This is a standard input box, nothing fancy.
The attributes I need to assign are:  type="text" id="dept1", name="dept1 and size="5".  Note, on name and dept, the numeric is appended to "dept" and is the row number.

C. Text- insert the row number. For example: <td width="40" size="2" align="center">5</td>".  Need to assign width and align attributes.  I'm not so sure "size" is relevant.


I know I must get the html tag attributes assigned correctly.  For example, the width goes with the <td> and not with the <input> tag.  The name, type size, value and id go with the <input> tag.  

Below is my attempt to create these 3 types of cells.  I get errors on the input box because of "width".  Also, javascript chokes and dies on my CSS code. I have no idea how to assign css only to a cell.

How do I get the attributes assigned to the correct html element (input box width and css in a cell) using javascript and DOM?


Thanks much!!!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Input Box - <td width="40"><input name="dept1" type="text" size="5"  value=""/></td>
-------------------------------------------------------------------------------------
  var cell2 = row.insertCell(2);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'bu' + iteration;
  el.id = 'bu' + iteration;
  el.size = 5;
  el.width = 40;   <<<--- This, I believe, is wrong? Width should go with <td></td>
  el.appendChild(el);
 
 
CSS - <td width="2" bgcolor="#7D7D7D" top-margin="2"></td>
----------------------------------------------------------
  var cell0 = row.insertCell(0);
  var el = document.createElement('class');  <<<--very lame, class is not correct, but don't know what to use for css?
  var el.style = document.attribute("style", "width: 2px; " + "bgcolor: #7D7D7D; " + "top-margin: 2px;");
  cell0.appendChild(el);
 
 
TEXT - <td width="40" size="2" align="center">1</td>
-------------------------------------------------------
  var cell1 = row.insertCell(1);
  var textNode = document.attribute("style", "align: center; " + iteration);
  cell1.appendChild(textNode);
 
where itteration is the row number.
 
Related Solutions
 
Loading Advertisement...
 
[+][-]09/23/08 09:32 PM, ID: 22556760Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Document Object Model, JavaScript
Tags: DOM javascript
Sign Up Now!
Solution Provided By: hielo
Participating Experts: 2
Solution Grade: A
 
[+][-]09/26/08 02:36 AM, ID: 22577835Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10/26/08 07:40 AM, ID: 22807344Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_2_20070628