
December 7th, 2012, 05:22 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 7
Time spent in forums: 3 h 16 m 32 sec
Reputation Power: 0
|
|
|
Don't get it :-(
Hi all,
What I want to do is to highlight some fields in a table on the same row with two clicks and fill the gap in between.
Used this code:
Code:
<html>
<head>
<script>
var tableColumns;
var tableRows;
var highlightColor;
var startid;
function initTable ( columns, rows, highlight )
{
tableColumns = columns;
tableRows = rows;
highlightColor = highlight;
var column;
var row;
startid = '-1.-1';
document.writeln('<TABLE border="0" cellpadding="0" cellspacing="3" style="border: 1px solid #808080" ><TBODY>');
for ( row = 1; row <= rows; row++ )
{
document.writeln('<TR>');
for ( column = 1; column <= columns; column++ )
{
document.writeln('<TD id="' + column + '.' + row + '" onclick="submitSelection( this.id );" width="35" height="35" style="border: 1px solid #808080" > </TD>');
}
document.writeln('</TR>');
}
document.writeln('<TR><TD id="tableSize" colspan="' + tableColumns + '" align="center" style="border: 1px solid #808080;font-family: Arial, Helvettica; font-size: 10pt;" height="35">0x0</TD></TR></TBODY></TABLE>');
}
function submitSelection ( id )
{
var actualid = id.split('.');
var tempstartid = startid.split('.');
var startcol;
var endcol;
var column;
startcol = 0;
endcol = 0;
// 1st click
if (startid == '-1.-1')
{
startid = id;
document.getElementById( id ).style.backgroundColor = highlightColor;
}
else
{
// same row
if (actualid[1] == tempstartid[1])
{
//startcolum < endcolumn
if( tempstartid[0] <= actualid[0] )
{
startcol = tempstartid[0];
endcol = actualid[0];
}
else
{
startcol = actualid[0];
endcol = tempstartid[0];
}
// fill out
for (column = startcol; column <= endcol; column++)
{
document.getElementById( column + '.' + actualid[1] ).style.backgroundColor = highlightColor;
}
// reset start
startid = '-1.-1';
}
}
}
initTable ( 31, 5, '#004080' );
</script>
</head>
<body>
</body>
</html>
What I don't get is why it's not working all the time?? The problem seems to be:
Code:
//startcolum < endcolumn
if( tempstartid[0] <= actualid[0] )
{
startcol = tempstartid[0];
endcol = actualid[0];
}
else
{
startcol = actualid[0];
endcol = tempstartid[0];
}
even if tempstartid[0] <= actualid[0] the elsepart is executed ???
Or is it just on IE9 not working ???
Any help is highly appreciated!
TIA
acki4711
|