what are some other ways to write the following. i have a table of 3 rows. Each row has a column with 3 checkboxes and another column with just a textbox.
What I want to happen is when the values are loaded from the database, if a row has any of its checkboxes checked or its textbox is not equal to blank highlight that row.
<table border="1" id="distributionTable">
<tr>
<td>Full Run</td>
<td><input type="checkbox" class="deliveryAction" name="Collection[0].IsHome" /> H
<input type="checkbox" class="deliveryAction" name="Collection[0].IsRack" /> R
<input type="checkbox" class="deliveryAction" name="Collection[0].IsRunOut" /> O</td>
<td><input type="text" name="Collection[0].Quantity" class="quantity" /></td>
</tr>
<tr>
<td>City Zones</td>
<td><input type="checkbox" class="deliveryAction" name="Collection[1].IsHome" /> H
<input type="checkbox" class="deliveryAction" name="Collection[1].IsRack" checked="checked" /> R
<input type="checkbox" class="deliveryAction" name="Collection[1].IsRunOut" /> O</td>
<td><input type="text" name="Collection[1].Quantity" class="quantity" /></td>
</tr>
<tr>
<td>12345</td>
<td><input type="checkbox" class="deliveryAction" name="Collection[2].IsHome" /> H
<input type="checkbox" class="deliveryAction" name="Collection[2].IsRack" /> R
<input type="checkbox" class="deliveryAction" name="Collection[2].IsRunOut" /> O</td>
<td><input type="text" name="Collection[2].Quantity" class="quantity" value="1000" /></td>
</tr>
</table>
here’s the jquery i wrote:
$('#distributionTable tr').each(function(){
$this = $(this);
var hascheck = false;
$this.find('.deliveryAction').each(function(){
if (this.checked){
hascheck = true;
return false;
}
});
if (hascheck)
{
$(this).css('background-color', 'red');
}
if ($this.find('.quantity').val() != ''){
$(this).css('background-color', 'orange');
}
});
You could do something like this (assuming that there is one text input per row):
Demo: http://jsfiddle.net/ambiguous/XXBWP/