• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 601
  • Last Modified:

Aligning Table Cells to Top.

Working on script that will dynamically generate tables from an array, below I have provided a portion of it.
I've tried everything but can't seem to get the data in the cells to align to the top.  I've tried valign = top, style.valign = top in the TR, TD tags.  Even trying to put the data in the cell into a <span> tag with valigns into that.  Nothing seems to align it top.
Though strangly most will work fine to align it left/right or center.


<HTML>
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<STYLE></STYLE>



<SCRIPT language="JavaScript">

var nh = Array(
{"key": "1234", "ticket1": "PM7654321", "status": "Open", "date": "Nov 14, 2003", "text": "Text Line 1", "alert": "0", "modified": "0"},
{"key": "1235", "ticket1": "PM7654322", "status":"Open", "date": "Nov 13, 2003", "text": "Text Line 2", "alert": "0", "modified": "0"},
{"key": "1236", "ticket1": "PM7654323", "status": "Open", "date": "Nov 15, 2003", "text": "Text Line 3", "alert": "1", "modified": "0"},
{"key": "1237", "ticket1": "PM7654324", "status": "Open", "date": "Nov 14, 2003", "text": "Text Line 4", "alert": "0", "modified": "0"}
);



function nhWrite(id)
{
var data_array = eval(id);
  var newTR, tdTICKET, tdSTATUS, tdOPENDATE, tdANALYST1, tdANALYST2, tdANALYST3, tdANALYST4;
  var inptTICKET1, inptTICKET2, inptTICKET3, inptTICKET4, newBR;
  var tdTEXT, tdACTIONTEAM, tdACTIONLOG;
  var newTR, newTD, newTD1, newTD2, newTD3, newINPUT;

  var newTable = document.createElement("table");  
  newTable.setAttribute("border", "1");

  var newTBody = document.createElement("tbody");
    newTBody.setAttribute("VALIGN", "TOP");
    newTBody.setAttribute("ALIGN", "LEFT");
    newTBody.style.valign = "TOP";

  for(var i = 0; i < data_array.length; i++)
  {
    newTR = document.createElement("tr");
    newTR.style.textalign = "TOP";

    if ( data_array[i].alert == "1") { newTR.style.backgroundColor = "#FFB6C1"; };
 
    tdTICKET = document.createElement("td");
    //tdTICKET.style.textalign = "TOP";
    //tdTICKET.setAttribute("VALIGN", "TOP");
    //tdTICKET.setAttribute("ALIGN", "LEFT");
    tdTICKET.setAttribute("width", "200");
    tdTICKET.setAttribute("height", "200");
    inptTICKET1 = document.createElement("input");
    inptTICKET1.setAttribute("type", "text");
    inptTICKET1.setAttribute("value", data_array[i]["ticket1"]);
    inptTICKET1.arrIdx = i;
        inptTICKET1.onchange = function(){ updateArray("nh", this.arrIdx, "ticket1", this.value) };
    tdTICKET.appendChild(inptTICKET1);
    newBR = document.createElement("br");


   
    tdSTATUS = document.createElement("td");
    tdSTATUS.setAttribute("VALIGN", "TOP");
    tdSTATUS.appendChild( document.createTextNode(data_array[i].status)  );
   
    tdOPENDATE = document.createElement("td");
    tdOPENDATE.appendChild( document.createTextNode(data_array[i].date)  );
   
    tdTEXT = document.createElement("td");
    newINPUT3 = document.createElement("textarea");
    newINPUT3.setAttribute("name", "textarea" + i);
    newINPUT3.appendChild ( document.createTextNode( data_array[i]["text"] + " - " + newINPUT3.name) );
    tdTEXT.appendChild(newINPUT3);

    newTR.appendChild(tdTICKET);
    newTR.appendChild(tdSTATUS);
    newTR.appendChild(tdOPENDATE);
    newTR.appendChild(tdTEXT);

    newTBody.appendChild(newTR);
  }
newTable.appendChild(newTBody);

var divlayer = document.getElementById(id);

divlayer.appendChild(newTable);

}

function updateArray (arrayName, arrayNumber, arrayHash, newValue)
{
    var array = eval(arrayName);
    array[arrayNumber][arrayHash] = newValue;
    array[arrayNumber]["modified"] = "1";
}

</SCRIPT>


</HEAD>
<BODY onLoad="nhWrite('nh');">

      <div ID='nh'>
      </div>

</BODY>
</HTML>


Thanks
-=[ Felix ]=-
0
Felix2000
Asked:
Felix2000
  • 2
1 Solution
 
monvelasquezCommented:
try this..


...
tdTICKET.style.verticalAlign = "TOP";
...
tdSTATUS.style.verticalAlign = "TOP";
...
tdOPENDATE.style.verticalAlign = "TOP";
...
tdTEXT.style.verticalAlign = "TOP";
...

0
 
Felix2000Author Commented:
Genius! Worked Perfectly... too bad the million references I checked made no mention of verticalalign...


Thanks
-=[ Felix ]=-
0
 
monvelasquezCommented:
next time you may want to search for CSS atributes...
attributes that have a dash ( "-" ) in their names are
usually converted to javascript by removing the dash
and capitalizing the next letter.

ex. CSS attribute for VALIGN is vertical-align. and if you want to use it in javascript
you use style.verticalAlign...

works great most of the time..
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now