I have a table
<table>
<tr class ="entry1">
<td class = "my_cell" name ="point" >
<td class = "my_cell" name ="distance1" >
<td class = "my_cell" name ="distance2" >
</tr>
<tr class ="entry2">
<td class = "my_cell" name ="point" >
<td class = "my_cell" name ="distance1" >
<td class = "my_cell" name ="distance2" >
</tr>
</table>
If any of the fields with the name "distance1" or "distance2" is filled then the corresponding text box in the same row (not in the other row)with the name "point" should be filled ,if not then a erro开发者_开发技巧r message should be printed.
If the text field with the name "point" is filled then the corresponding test boxes "distance1" or "distance2" in the same not in the other row) row should be filled or a error message must be printed
Something like this?
$('input[name=distance1], input[name=distance2]').change(function() {
if (this.value != "") {
$(this).closest('tr').find('[name=point]').val(filling); //whatever the value should be
} else {
// show error message
}
});
It isn't flawless, you probably want a better check than this.value.
After the edit (I assumed inputs, now it's less dynamic):
$('table tr').each(function() {
var row = $(this);
if (row.find('[name=distance1]').text() != "" || row.find('[name=distance1]').text() != "") {
row.find('[name=point]').text(filling); //whatever you want to set
} else {
// show error message
}
});
This runs once, and you need something similar for the point-exception. But it's not specific enough to create it now.
精彩评论