473,387 Members | 1,569 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,387 software developers and data experts.

dynamic table setting td align in IE

Hello,

Problems with IE, works fine in FireFox.

Building tables with javascript. Everything works fine until I resize an inputfield, type text, in a td. When that is done I want all the td's in the same column to align = center so their inputfields, type text, that now are smaller than the one I resized end up in the middle, straight below the bigger one.


I've tried currentTd.setAttribute("align", "center") and currentTd.align = "center".

I know I'm looking at the right td and all, setting other things like borderColor etc works fine but not the align.

Any ideas? Thank you for taking your time.

Regards,
Magnus
Nov 19 '08 #1
9 4771
acoder
16,027 Expert Mod 8TB
Can you post your code where the problem occurs?
Nov 20 '08 #2
Couldn't delete. This should have been a reply to previous post.
Nov 20 '08 #3
Can you post your code where the problem occurs?



Hi,

The code below shows how I create the tablerows and tabledata. After that a user can mark any of the toprow columns and increase the size of the <input type="text"> node. This is done by grabbing the node, getting the size, adding 1 and reseting it. That's the last code I added.

When the resizing is done I expect the items in the same column, straight below to line up in the center of the td, or right when I set align so.

Works fine in FF but not in IE. Really really annoying.

Expand|Select|Wrap|Line Numbers
  1. // Loop nr of rows
  2. for(var r = 0; r < nrRows; r++) {
  3. // Create current row
  4. var currTr = document.createElement("tr");
  5.  
  6. // Loop nr of columns for each row.
  7. for(var c = 0; c < nrCols; c++) {
  8. // Create current column.
  9. var currTd = document.createElement("td");
  10.  
  11. // Figure out current td's id
  12. var currTdId = "matrixtd_" + currMatrixNr + "_td_" + itemCnt;
  13. currTd.setAttribute("id", currTdId);
  14. currTd.setAttribute("align", "center");
  15. currTd.style.width = "50px";
  16. currTd.style.border = "1px dotted #AAAAAA";
  17.  
  18.  
  19. // Create element to go inside td
  20. var tdContent = document.createElement("input");
  21. tdContent.setAttribute("type", "text");
  22. tdContent.setAttribute("size", 10);
  23. tdContent.setAttribute("id", "matrixText_" + currMatrixNr + "_" + itemCnt);
  24.  
  25. // Create element to go inside td
  26. var tdContent = document.createElement("input");
  27. tdContent.setAttribute("type", "text");
  28. tdContent.setAttribute("size", 10);
  29.  
  30.  
  31.  
  32.  
  33. ******CODE TO RESIZE*******
  34. else if(tmp[0] == "matrixtd") {
  35. var curr_item_child = curr_item.firstChild;
  36. var curr_size = curr_item_child.getAttribute("size");
  37. var new_size = parseInt(curr_size) + parseInt(param);
  38.  
  39. if(new_size < 1) {
  40. new_size = 1;
  41. }
  42.  
  43. curr_item_child.setAttribute("size", new_size);
Nov 20 '08 #4
acoder
16,027 Expert Mod 8TB
Is this all of the code? I notice no appendChild() statements.

Is this a problem when resizing or when creating the table?
Nov 20 '08 #5
Is this all of the code? I notice no appendChild() statements.

Is this a problem when resizing or when creating the table?

No, this is far from all the code but this would be the parts involved in creating, resizing and aligning the table and it's content. The appendChild() statements comes right after the first bit of code.

It's as if IE doesn't respond to setAttribute("align", "center"). Just to be sure I'm barking up the right tree I've tried all sorts of combinations. I've set it to right, changed colors, fonts and borders. I've tried going for the property by typing currTd.align. It all works in FF but not IE...well, borders etc works for IE too but not the align.
Nov 21 '08 #6
Is this all of the code? I notice no appendChild() statements.

Is this a problem when resizing or when creating the table?

This is the entire code for creating the table.

Expand|Select|Wrap|Line Numbers
  1. //
  2. // Function to create matrix.
  3. //
  4. function createMatrix() {
  5.     var contentDiv = document.getElementById("div_content");
  6.     var matrix = document.getElementById("matrix");
  7.     var nrCols = document.getElementById("nrMatrixColumns");
  8.     var nrRows = document.getElementById("nrMatrixRows");
  9.  
  10.     // Variable to keep track of which item in matrix we're creating.
  11.     // Used in name and id.
  12.     var itemCnt = 1;
  13.  
  14.     // Add one to both rows and cols since we need column and row names.
  15.     nrCols = parseInt(nrCols.value) + 1;
  16.     nrRows = parseInt(nrRows.value) + 1;
  17.  
  18.     // Calculate width for table. Nr columns * 50
  19.     var defaultTableWidth = (nrCols * 50) + "px";
  20.  
  21.     // Figure out current matrix number, in this question.
  22.     var currMatrixNr = parseInt(matrix.value) + 1;
  23.  
  24.  
  25.     //
  26.     // Start creating table.
  27.     //
  28.  
  29.     // Table
  30.     var myTable = document.createElement("table");
  31.     myTable.style.width = defaultTableWidth;
  32.     myTable.style.position = "absolute";
  33.     myTable.style.top = "10px";
  34.     myTable.style.left = "10px";
  35.     myTable.style.border = "1px dotted #AAAAAA";
  36.     myTable.setAttribute("id", "matrix_" + currMatrixNr);
  37.     myTable.ondblclick = function (evt) { beenSelected(this);};
  38.  
  39.     // Tablebody
  40.     var myTableBody = document.createElement("tbody");
  41.  
  42.     // Loop nr of rows
  43.     for(var r = 0; r < nrRows; r++) {
  44.         // Create current row
  45.         var currTr = document.createElement("tr");
  46.  
  47.         // Loop nr of columns for each row.
  48.         for(var c = 0; c < nrCols; c++) {
  49.             // Create current column.
  50.             var currTd = document.createElement("td");
  51.  
  52.             // Figure out current td's id
  53.             var currTdId = "matrixtd_" + currMatrixNr + "_td_" + itemCnt;
  54.             currTd.setAttribute("id", currTdId);
  55.             currTd.setAttribute("align", "center");
  56.             currTd.style.width = "50px";
  57.             currTd.style.border = "1px dotted #AAAAAA";            
  58.  
  59.  
  60.             // Create element to go inside td
  61.             var tdContent = document.createElement("input");
  62.             tdContent.setAttribute("type", "text");
  63.             tdContent.setAttribute("size", 10);
  64.             tdContent.setAttribute("id", "matrixText_" + currMatrixNr + "_" + itemCnt);
  65.  
  66.             // Is this first row in table? Columnnames.
  67.             if(r == 0) {
  68.  
  69.                 // Check if first td, top left
  70.                 if(itemCnt != 1) {
  71.                     currTd.onclick = function (evt) { beenSelected(this);};
  72.                     tdContent.style.background = "#EEEEEE";
  73.                 }
  74.                 else {                
  75.                     tdContent.style.background = "#AAAAAA";
  76.                 }
  77.  
  78.                 // Append tdContent
  79.                 currTd.appendChild(tdContent);
  80.             }
  81.             else { // Following rows. Rownames
  82.  
  83.                 // Check if first column, is so allow user to set rowname.
  84.                 if(c == 0) {
  85.                     currTd.onclick = function (evt) { beenSelected(this);};
  86.                     tdContent.style.background = "#EEEEEE";
  87.                 }
  88.  
  89.                 // Append tdContent
  90.                 currTd.appendChild(tdContent);
  91.             }
  92.  
  93.             // Add td to tr
  94.             currTr.appendChild(currTd);
  95.  
  96.             // Increment item counter.
  97.             itemCnt++;
  98.         }
  99.  
  100.         // Append tr to tablebody
  101.         myTableBody.appendChild(currTr);
  102.     }
  103.  
  104.     // Append table body to table and table to content div.
  105.     myTable.appendChild(myTableBody);
  106.     contentDiv.appendChild(myTable);
  107.  
  108.     // Update keep_track
  109.     matrix.value = currMatrixNr
  110. }
Nov 21 '08 #7
acoder
16,027 Expert Mod 8TB
This may be a pure CSS bug in IE. If you try the same code as pure HTML/CSS without any JavaScript with one input element larger than the ones below, do you see the same problem? You may find this article useful.
Nov 21 '08 #8
This may be a pure CSS bug in IE. If you try the same code as pure HTML/CSS without any JavaScript with one input element larger than the ones below, do you see the same problem? You may find this article useful.

Hi,

Yes, I code a little piece and tried it, works fine in IE too. Here's the code.


Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html>
  3.  
  4.     <head>
  5.         <script language="javascript">
  6.             function showWidth() {
  7.                 var tmp1 = document.getElementById("td_1");
  8.                 var tmp2 = document.getElementById("td_2");
  9.                 alert("1: " + tmp1.scrollWidth + " / " + tmp1.scrollHeight + " offsets: " + tmp1.offsetWidth + " / " + tmp1.offsetHeight +
  10.                         "\n2: " + tmp2.scrollWidth + "  /  " + tmp2.scrollHeight + " offsets: " + tmp2.offsetWidth + " / " + tmp2.offsetHeight);
  11.             }
  12.  
  13.             function moveRight() {
  14.                 var tmp = document.getElementById("moveTd");
  15.  
  16.                 if(tmp.align == "left") {
  17.                     tmp.align = "center";
  18.                 }
  19.                 else if(tmp.align == "center") {
  20.                     tmp.align = "right";
  21.                 }
  22.                 else if(tmp.align == "right") {
  23.                     tmp.align = "left";
  24.                 }
  25.             }
  26.         </script>
  27.     </head>
  28.  
  29. <body>
  30.  
  31.     <table style="border:1px dotted #AAAAAA">
  32.         <tr>    
  33.             <td style="border:1px dotted #AAAAAA"><input type="text" size="10"></td>
  34.             <td style="border:1px dotted #AAAAAA"><input type="text" size="20"></td>
  35.             <td style="border:1px dotted #AAAAAA"><input type="text" size="10"></td>
  36.         </tr>
  37.         <tr>    
  38.             <td style="border:1px dotted #AAAAAA"><input type="text" size="10"></td>
  39.             <td align="left" id="moveTd" style="border:1px dotted #AAAAAA"><input type="text" size="10"></td>
  40.             <td style="border:1px dotted #AAAAAA"><input type="text" size="10"></td>
  41.         </tr>
  42.         <tr>    
  43.             <td style="border:1px dotted #AAAAAA"><input type="text" size="10"></td>
  44.             <td style="border:1px dotted #AAAAAA"><input type="text" size="10"></td>
  45.             <td style="border:1px dotted #AAAAAA"><input type="text" size="10"></td>
  46.         </tr>
  47.     </table>
  48.  
  49.  
  50.     <div>
  51.     <div id="container" style="position: relative; top: 20px; left: 20px; border: 1px dotted #AAAAAA">
  52.         <div id="row_1">
  53.             <div id="td_1" style="position: relative; top: 2px; left: 3px; float: left; padding: 2px 2px"><input type="text" size="10"></div>
  54.             <div id="td_2" style="position: relative; top: 2px; left: 3px; float: left; padding: 2px 2px;"><input type="text" size="20"></div>
  55.             <div id="td_3" style="position: relative; top: 2px; left: 3px; padding: 2px 2px;"><input type="text" size="10"></div>
  56.         </div>
  57.  
  58.         <div id="row_1">
  59.             <div id="td_4" style="position: relative; top: 2px; left: 3px; float: left; padding: 2px 2px"><input type="text" size="10"></div>
  60.             <div id="td_5" style="position: relative; top: 2px; left: 3px; float: left; padding: 2px 2px;"><input type="text" size="10"></div>
  61.             <div id="td_6" style="position: relative; top: 2px; left: 3px; padding: 2px 2px;"><input type="text" size="10"></div>
  62.         </div>
  63.  
  64.     </div>
  65.     </div>
  66.  
  67.     <button type="button" onclick="showWidth()" style="position: relative; top: 20px;">Show width/height</button>
  68.     <button type="button" onclick="moveRight()" style="position: relative; top: 20px;">Move right</button>
  69.  
  70. </body>
  71. </html>
Nov 21 '08 #9
acoder
16,027 Expert Mod 8TB
I'm not sure what the problem might be, but if you look at the innerHTML of the table in IE, you'll see that the align gets set to "middle" instead of "center" for some reason.
Nov 23 '08 #10

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

Similar topics

2
by: Tom | last post by:
I would like to know if an .asp case statement can contain HTML elements. I am building an application that I would like to have dynamic choices. The dynamic part would be built in the a case...
7
by: Abraham Luna | last post by:
how do i stop the dynamic validators from breaking explorer if i use a dynamic validator and move to a different control it breaks explorer and i can type in the page when i'm not supposed to....
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
0
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value &...
0
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value &...
0
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value &...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...
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.