473,537 Members | 2,984 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic table setting td align in IE

6 New Member
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 4781
acoder
16,027 Recognized Expert Moderator MVP
Can you post your code where the problem occurs?
Nov 20 '08 #2
asyouwish
6 New Member
Couldn't delete. This should have been a reply to previous post.
Nov 20 '08 #3
asyouwish
6 New Member
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 Recognized Expert Moderator MVP
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
asyouwish
6 New Member
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
asyouwish
6 New Member
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 Recognized Expert Moderator MVP
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
asyouwish
6 New Member
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 Recognized Expert Moderator MVP
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
2355
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 statment that will output based upon the value of the option evaluated. This example only shows one case statement but there are eight case...
7
1882
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. thank you.
0
3370
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 within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to...
2
5009
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 is this, I have a page which uses multiple postbacks to generate a list of dynamic text boxes with appropriate labels. However, when I do the final...
0
1427
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 & update to the database based on the hidden ID. DELETE ALL will delete everything the databse.
0
1968
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 & update to the database based on the hidden ID. DELETE ALL will delete everything the databse.
0
1702
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 & update to the database based on the hidden ID. DELETE ALL will delete everything the databse.
3
4198
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 value (text value) here is the code if possible please help me Thanks beforehand <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"...
0
7361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7531
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7275
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...
0
7642
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...
0
5824
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5218
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...
0
3345
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...
0
3341
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
924
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.