Forum Moderators: open
var cells = document.getElementById('checkRow').getElementsByTagName('td'); var cells = document.getElementsTagName('tr').getElementsByTagName('td');?
foreach ($bookings as $rm => $dates) {
echo "<TR><TD>$rm</TD>";
foreach ($dates as $d => $booked) {
if booked){
echo "<TD style='background:red; colour:white'> </TD>\n";
}
else {
echo "<TD style='background:green; colour:white'>
<INPUT type='checkbox' name='book[$rm][]' value='$d'>
</TD>\n"; }
echo "<td id='$d' width='20' class=no onclick='doselection(this)'<input type=hidden id=\"optval\" name=\"book[$rm][]\" value=\"\"> </td>";
<body>
<table align='left'TABLE border='4' bordercolor='#A6A6D2' cellspacing='1' cellpadding='0' id='bookingscal'>
<TR><TH>Room</TH>
<TH width=20px>13</TH>
<TH width=20px>14</TH>
<TH width=20px>15</TH>
<TH width=20px>16</TH>
<TH width=20px>17</TH>
<TH width=20px>18</TH>
<TH width=20px>19</TH>
<TH width=20px>20</TH>
<TH width=20px>21</TH>
<TH width=20px>22</TH>
</TR>
<tr><td>101</td>
<td id=2005-09-13 width="20" class=no onclick="doselection(this)"> </td>
<td id=2005-09-14 width="20" class=no onclick="doselection(this)"> </td>
<td id=2005-09-15 width="20" class=no onclick="doselection(this)"> </td>
<td id=2005-09-16 width="20" class=no onclick="doselection(this)"> </td>
<td id=2005-09-17 width="20" class=no onclick="doselection(this)"> </td>
<td id=2005-09-18 width="20" class=no onclick="doselection(this)"> </td>
<td id=2005-09-19 width="20" class=no onclick="doselection(this)"> </td>
<td id=2005-09-20 width="20" class=no onclick="doselection(this)"> </td>
<td id=2005-09-21 width="20" class=no onclick="doselection(this)"> </td>
<td id=2005-09-22 width="20" class=no onclick="doselection(this)"> </td>
</tr>
<tr><td>102</td>
<td id=2005-09-13 class=no onclick="doselection(this)"> </td>
<td id=2005-09-14 class=no onclick="doselection(this)"> </td>
<td id=2005-09-15 class=no onclick="doselection(this)"> </td>
<td id=2005-09-16 class=no onclick="doselection(this)"> </td>
<td id=2005-09-17 class=no onclick="doselection(this)"> </td>
<td id=2005-09-18 class=no onclick="doselection(this)"> </td>
<td id=2005-09-19 class=no onclick="doselection(this)"> </td>
<td id=2005-09-20 class=no onclick="doselection(this)"> </td>
<td id=2005-09-21 class=no onclick="doselection(this)"> </td>
<td id=2005-09-22 class=no onclick="doselection(this)"> </td>
</tr>
</table><br><br>
</body>
</html>
[/code]
Give each "room row" (the <tr> element) an id - the room number.
Then change this bit in the loop of the getValues function from
vals[vals.length] = cell.id; to
vals[vals.length] = cell.parentNode.id+'@'+cell.id; (@ - or a delimiter of your choice)
Now, you'll receive a double-delimited string value,
room_no@date:room_no@date:....
which you'll have to parse at the server (not beyond my capabilities, but I don't know exactly what you're doing with it).
PS You could, if you don't want to bother with extra ids, use the content of the row's first cell (since it carries the room No already)
// incl. a quick space trim
vals[vals.length]
= cell.parentNode.cells[0].innerHTML.replace(/^\s+¦\s+$/g,'')+'@'+cell.id;
..but that leaves the script a little vulnerable.
Just means that the script relies on the fact that the first cells don't carry the numbers as, say, images, for instance. I sometimes think that the script relying on the actual content is a vulnerability.
get the result into an multi dimensional array
That kind of thing would do equally well, but I don't think you need a full 'table' there, just 2 correlations of info by index:
// ie: date = dates[cell.cellIndex-1] // not the 1st cell
dates =
[
'2005-09-13',
'2005-09-14',
'2005-09-15',
'2005-09-16',
'2005-09-17',
'2005-09-18',
'2005-09-19',
'2005-09-20',
'2005-09-21',
'2005-09-22'
]// ie: room = rooms[cell.parentNode.rowIndex-1] // not the header row
rooms = [101,102]
#bookingscal td:first-child{ background-color:red;}
but for IE, I don't know. It may be possible by messing around using <colgroup> elements.
The less brain-taxing way, is to take a step back and attach a class attribute to every cell in that column.