/    Sign up×
Community /Pin to ProfileBookmark

Dense Table/Form layout problem

Greetings,

I have a problem that I am sure others have already solved. The problem is that I need to present a table with forms. I cannot put the entire table into one form as there as some very real limitations on the server concerning the number of input elements. I cannot have a form per row as the FORM element is not a legal element within the TR element, nor within the TABLE element.

There are customer restrictions on the way the data are displayed, so I cannot have each row as a visibly different table.

Briefly, the form needs to look sort of like this (yeah, this isn’t code, but it displays like what I want in this question):

[CODE]
[B]Header1 Header2 Header3 Header4[/B]
Data1 Data2 Data3 Data4
DataA DataB DataC DataD [B]Submit[/B]
Data1 Data2 Data3 Data4
DataA DataB DataC DataD [B]Submit[/B]
Data1 Data2 Data3 Data4
DataA DataB DataC DataD [B]Submit[/B]

[/CODE]

Currently, I have implemented this as a series of tables, of one row each, with the Submit button on the right for those rows that are actually forms (see the code below). When presented “raw”, this looks awful as the columns do not align. Some Javascript fixes that but it has serious limitations. Very serious.

So, given what it looks like, how can I do this “properly”?

Brace yourself, here’s a sample of the encoded table/form. It has passed validation so you should be able to Cut&Paste and view it with a browser.

(Sorry I don’t have a site to download it from)

[CODE]<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html><head>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<title>Example of Dense Form/Table</title>
<style type=”text/css”>
<!–
INPUT { font-size: small; }
TD.Data { border: thin solid; }
TH.Data { border: thin solid; }
TABLE.Data { border-collapse: collapse; text-align: left; font-size: small; }
–>
</style>
</head><body>
<noscript>
<h1>Your browser <strong>must</strong> support JavaScript for this page to be properly displayed!</h1>
</noscript>
<script type=”text/javascript” language=”javascript”>
window.onresize = getColWidths;
window.onload = getColWidths;

var hasInnerText = false; // IE different from Mozilla for getting text strings
function forceMinWidth()
{
// true for IE, false for mozilla/firefox
hasInnerText = (document.getElementsByTagName(“body”)[0].innerText != undefined) ? true : false;
var myRows = document.getElementsByTagName(“tr”);
for(var j in myRows) // set each column width to same value to enforce line-up
{
var name = myRows[j].id;
if(name && name.match(“^(headRow|row_\d+)$”))
{
var cells = myRows[j].cells;
for(var i = 0; i < (cells.length – 1); i++)
{
//cells[i].width = maxWidths[i] – 3;
cells[i].style.width = “10px”;
cells[i].noWrap = false;
}
}
}
}
function getColWidths() // align columns on multiple tables to feign a single table. Sigh.
{
forceMinWidth();

// true for IE, false for mozilla/firefox
hasInnerText = (document.getElementsByTagName(“body”)[0].innerText != undefined) ? true : false;
var maxWidths = new Array(11);
for(var i = 0; i < maxWidths.length; i++)
{
maxWidths[i] = 0;
}
var myRows = document.getElementsByTagName(“tr”);
for(var j in myRows) // find max width for each column
{
var name = myRows[j].id;
// Only look at the table header and threshold data rows
if(name && name.match(“^(headRow|row_\d+)$”))
{
var cells = myRows[j].cells;
var cMsg = “Cell offsetWidths for ” + name + ” “;
for(var i = 0; i < (cells.length – 1); i++)
{
if(maxWidths[i] < cells[i].offsetWidth)
maxWidths[i] = cells[i].offsetWidth;
}
}
}
for(var j in myRows) // set each column width to same value to enforce line-up
{
var name = myRows[j].id;
if(name && name.match(“^(headRow|row_\d+)$”))
{
var cells = myRows[j].cells;
for(var i = 0; i < (cells.length – 1); i++)
{
//cells[i].width = maxWidths[i] – 3;
cells[i].style.width = “” + (maxWidths[i] – 3) + “px”;
if(hasInnerText)
{
// IE has different rendering rules
cells[i].style.width = “” + (maxWidths[i] – 5) + “px”;
}
else
{
// Mozilla/Seamonkey/Firefox
cells[i].style.width = “” + (maxWidths[i] – 3) + “px”;
}
cells[i].noWrap = true;
}
}
}
}
function getText(aCell)
{
// hasInnerText = (document.getElementsByTagName(“body”)[0].innerText != undefined) ? true : false;
var value = hasInnerText ? aCell.innerText : aCell.textContent;
return value;
}
function submitform(rowID,formID)
{
if (confirm (“You really want to do this?”))
{
return true;
}
return false;
}
</script>

<table class=”Data” border=”0″>
<tr id=”headRow” style=”text-align: center;” class=”Data”>
<th class=”Data” nowrap=”nowrap”>Label</th>
<th class=”Data” nowrap=”nowrap”>Type</th>
<th class=”Data” nowrap=”nowrap”>Major&nbsp;Low</th>
<th class=”Data” nowrap=”nowrap”>Minor&nbsp;Low</th>
<th class=”Data” nowrap=”nowrap”>Value</th>
<th class=”Data” nowrap=”nowrap”>Minor&nbsp;High</th>
<th class=”Data” nowrap=”nowrap”>Major&nbsp;High</th>
<th class=”Data” nowrap=”nowrap”>Hysteresis</th>
<th class=”Data” nowrap=”nowrap”>Range&nbsp;Low</th>
<th class=”Data” nowrap=”nowrap”>Range&nbsp;High</th>
<th style=”border: medium none ;”>&nbsp;</th>
</tr>
</table>

<table class=”Data” border=”0″>
<tr id=”row_1″>
<td class=”Data” nowrap=”nowrap”>PsOk</td>
<td class=”Data” nowrap=”nowrap”>6</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>0 (ok)</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td style=”border: medium none ;”>&nbsp;</td>
</tr>
</table>

<form name=”ModThresholds_2″ action=”/ModuleThresholds.html?ModuleID=4.12″ method=”post” style=”margin: 0pt;” onsubmit=”javascript: return submitform(‘row_2′,’ModThresholds_2’)”>
<table class=”Data” border=”0″>
<tr id=”row_2″>
<td class=”Data” nowrap=”nowrap”>OutPwr</td>
<td class=”Data” nowrap=”nowrap”>1</td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almMajorLowLimit(4.12.2)” size=”9″ value=”-1″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almMinorLowLimit(4.12.2)” size=”9″ value=”-0.7″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”>2 (ok)</td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almMinorHighLimit(4.12.2)” size=”9″ value=”0.7″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almMajorHighLimit(4.12.2)” size=”9″ value=”1″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almHysteresis(4.12.2)” size=”9″ value=”0.1″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”>-3276.8</td>
<td class=”Data” nowrap=”nowrap”>3276.7</td>
<td style=”border: medium none;”><input style=”background: lightblue none;” value=”Apply” type=”submit”></td>
</tr>
</table>
</form>

<table class=”Data” border=”0″>
<tr id=”row_3″>
<td class=”Data” nowrap=”nowrap”>IntPs</td>
<td class=”Data” nowrap=”nowrap”>6</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>0 (ok)</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td class=”Data” nowrap=”nowrap”>N/A</td>
<td style=”border: medium none ;”>&nbsp;</td>
</tr>
</table>

<form name=”ModThresholds_6″ action=”/ModuleThresholds.html?ModuleID=4.12″ method=”post” style=”margin: 0pt;” onsubmit=”javascript: return submitform(‘row_6′,’ModThresholds_6’)”>
<table class=”Data” border=”0″>
<tr id=”row_6″>
<td class=”Data” nowrap=”nowrap”>LasBias</td>
<td class=”Data” nowrap=”nowrap”>1</td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almMajorLowLimit(4.12.6)” size=”9″ value=”-2″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almMinorLowLimit(4.12.6)” size=”9″ value=”-1″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”>2 (ok)</td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almMinorHighLimit(4.12.6)” size=”9″ value=”-0.01″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almMajorHighLimit(4.12.6)” size=”9″ value=”-0.001″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”><input name=”p2almHysteresis(4.12.6)” size=”9″ value=”0.001″ type=”text”></td>
<td class=”Data” nowrap=”nowrap”>-32.768</td>
<td class=”Data” nowrap=”nowrap”>32.767</td>
<td style=”border: medium none;”><input style=”background: lightblue none” value=”Apply” type=”submit”></td>
</tr>
</table>
</form>

</body></html>
[/CODE]

to post a comment
HTML

1 Comments(s)

Copy linkTweet thisAlerts:
@heb3authorOct 13.2006 — Well, I never got a response so I struggled some more. I finally decided that using the onfocus attribute for all form INPUT tags to set a variable indicating the row was the way to go. That way, I have one giant form containing the table, but when I submit, some JavaScript determines which row I was on and builds another form with those values and submits that form instead.

Crude, but it works. Here is some example code (sorry about the size):

[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Dense Table Form Solution</title>
<style type="text/css">
<!--
INPUT { font-size: small; }
TD.Data { border: thin solid; }
TH.Data { border: thin solid; }
TABLE.Data { border-collapse: collapse; text-align: left; font-size: small; }
-->
</style>
</head>
<body>
<noscript>
<h1>Your browser <strong>must</strong> support JavaScript for this page to be properly displayed!</h1>
</noscript>
<script type="text/javascript" language="javascript">
var currentRow = 0;
var hasInnerText = false; // IE different from Mozilla for getting text strings
function setRow(r)
{
currentRow = r;
}
function getText(aCell)
{
// hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
var value = hasInnerText ? aCell.innerText : aCell.textContent;
return value;
}
function submitform()
{
var rowID = currentRow;
var modID = "4.12"; // e.g., 4.12
var almSpec = modID + "." + rowID; // e.g., 4.12.6
hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
if (validateForm (rowID))
{
var thisRow = document.getElementById('row_' + rowID);
var almLabel = getText(thisRow.cells[0]);

var MajorLow = document.getElementsByName( 'p2almMajorLowLimit(' + rowID + ')' )[0].value;
var MinorLow = document.getElementsByName( 'p2almMinorLowLimit(' + rowID + ')' )[0].value;
var MinorHigh = document.getElementsByName( 'p2almMinorHighLimit(' + rowID + ')' )[0].value;
var MajorHigh = document.getElementsByName( 'p2almMajorHighLimit(' + rowID + ')' )[0].value;
var Hysteresis = document.getElementsByName( 'p2almHysteresis(' + rowID + ')' )[0].value;

var msg = "Save Module Thresholds for Alarm " + almLabel + "?n";
msg += "MajorLow=" + MajorLow + "n";
msg += "MinorLow=" + MinorLow + "n";
msg += "MinorHigh=" + MinorHigh + "n";
msg += "MajorHigh=" + MajorHigh + "n";
msg += "Hysteresis=" + Hysteresis;

if (confirm (msg))
{
var myForm = document.dummyForm; // form that will be submitted (not the main form!)
// Rename the inputs on the mini-form
myForm[0].name = "p2almMajorLowLimit(" + almSpec + ")"; // eg, p2almMajorLowLimit(4.12.7)
myForm[1].name = "p2almMinorLowLimit(" + almSpec + ")";
myForm[2].name = "p2almMinorHighLimit(" + almSpec + ")";
myForm[3].name = "p2almMajorHighLimit(" + almSpec + ")";
myForm[4].name = "p2almHysteresis(" + almSpec + ")";

// Populate values into mini-form
myForm[0].value = MajorLow;
myForm[1].value = MinorLow;
myForm[2].value = MinorHigh;
myForm[3].value = MajorHigh;
myForm[4].value = Hysteresis;

document.dummyForm.submit();
return false; // Don't submit the main form
}

}
return false;
}
function validateForm(rowID)
{
return true; // this is just a demo of a technique
}
</script>

<form name="dummyForm" action="/ModuleThresholds.html?ModuleID=4.12" method="post">
<input type=hidden name="p2almMajorLowLimit" value=0>
<input type=hidden name="p2almMinorLowLimit" value=0>
<input type=hidden name="p2almMinorHighLimit" value=0>
<input type=hidden name="p2almMajorHighLimit" value=0>
<input type=hidden name="p2almHysteresis" value=0>
</form>

<form name='ModThresholds' action='/ModuleThresholds.html?ModuleID=4.12'
method=post style='margin: 0pt'
onSubmit="javascript: return submitform();">
<table class=Data border=0>
<tr id="headRow" style="text-align: center;" class=Data>
<th class=Data>Label</th>

<th class=Data>Type</th>
<th class=Data>Major&nbsp;Low</th>
<th class=Data>Minor&nbsp;Low</th>
<th class=Data>Value</th>
<th class=Data>Minor&nbsp;High</th>

<th class=Data>Major&nbsp;High</th>
<th class=Data>Hysteresis</th>
<th class=Data>Range&nbsp;Low</th>
<th class=Data>Range&nbsp;High</th>
<th style="border: medium none;">&nbsp;</th>

</tr>

<tr id=row_1>
<td class=Data>PsOk</td>
<td class=Data>6</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>

<td class=Data>0 (ok)</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>

<td style='border: none'>&nbsp;</td>
</tr>

<tr id=row_2>
<td class=Data>OutPwr</td>
<td class=Data>1</td>
<td class=Data><input type=text name='p2almMajorLowLimit(2)' size=9 value='-1.1' onFocus="javascript: setRow(2)"></td>
<td class=Data><input type=text name='p2almMinorLowLimit(2)' size=9 value='-0.7' onFocus="javascript: setRow(2)"></td>

<td class=Data>2 (ok)</td>
<td class=Data><input type=text name='p2almMinorHighLimit(2)' size=9 value='0.7' onFocus="javascript: setRow(2)"></td>
<td class=Data><input type=text name='p2almMajorHighLimit(2)' size=9 value='1.1' onFocus="javascript: setRow(2)"></td>
<td class=Data><input type=text name='p2almHysteresis(2)' size=9 value='0.1' onFocus="javascript: setRow(2)"></td>
<td class=Data>-3276.8</td>
<td class=Data>3276.7</td>
<td style='border: none'><input type=submit style='background: lightblue;' Value=Apply onFocus="javascript: setRow(2)"></td>

</tr>

<tr id=row_3>
<td class=Data>IntPs</td>
<td class=Data>6</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>

<td class=Data>0 (ok)</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>

<td style='border: none'>&nbsp;</td>
</tr>

<tr id=row_4>
<td class=Data>Enable</td>
<td class=Data>6</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>

<td class=Data>0 (ok)</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>

<td style='border: none'>&nbsp;</td>
</tr>

<tr id=row_5>
<td class=Data>LasTemp</td>
<td class=Data>3</td>
<td class=Data>-20</td>
<td class=Data>-15</td>

<td class=Data>2 (ok)</td>
<td class=Data>15</td>
<td class=Data>20</td>
<td class=Data>1</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>

<td style='border: none'>&nbsp;</td>
</tr>

<tr id=row_6>
<td class=Data>LasBias</td>
<td class=Data>1</td>
<td class=Data><input type=text name='p2almMajorLowLimit(6)' size=9 value='-2.1' onFocus="javascript: setRow(6)"></td>
<td class=Data><input type=text name='p2almMinorLowLimit(6)' size=9 value='-1' onFocus="javascript: setRow(6)"></td>

<td class=Data>2 (ok)</td>
<td class=Data><input type=text name='p2almMinorHighLimit(6)' size=9 value='-0.01' onFocus="javascript: setRow(6)"></td>
<td class=Data><input type=text name='p2almMajorHighLimit(6)' size=9 value='-0.001' onFocus="javascript: setRow(6)"></td>
<td class=Data><input type=text name='p2almHysteresis(6)' size=9 value='0.001' onFocus="javascript: setRow(6)"></td>
<td class=Data>-32.768</td>
<td class=Data>32.767</td>
<td style='border: none'><input type=submit style='background: lightblue;' Value=Apply onFocus="javascript: setRow(6)"></td>

</tr>

<tr id=row_7>
<td class=Data>InPwr</td>
<td class=Data>1</td>
<td class=Data><input type=text name='p2almMajorLowLimit(7)' size=9 value='-15' onFocus="javascript: setRow(7)"></td>
<td class=Data><input type=text name='p2almMinorLowLimit(7)' size=9 value='-5' onFocus="javascript: setRow(7)"></td>
<td class=Data>2 (ok)</td>

<td class=Data><input type=text name='p2almMinorHighLimit(7)' size=9 value='15' onFocus="javascript: setRow(7)"></td>
<td class=Data><input type=text name='p2almMajorHighLimit(7)' size=9 value='45' onFocus="javascript: setRow(7)"></td>
<td class=Data><input type=text name='p2almHysteresis(7)' size=9 value='1' onFocus="javascript: setRow(7)"></td>
<td class=Data>-3276.8</td>
<td class=Data>3276.7</td>
<td style='border: none'><input type=submit style='background: lightblue;' Value=Apply onFocus="javascript: setRow(7)"></td>
</tr>

<tr id=row_8>
<td class=Data>Service</td>
<td class=Data>5</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>0 (ok)</td>

<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td class=Data>N/A</td>
<td style='border: none'>&nbsp;</td>

</tr>

</table>
</form>

</body>
</html>[/CODE]
×

Success!

Help @heb3 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...