I have a page at this link http://183.78.169.53/lp/addRoute6.php. You can press first the add button to have at least 5 rows. So then you can select the location for the first row. Then if you select the same location for second row if it is same with the previous it will automatically be selected to "Select Location". I have cater to this validation well with the codes below. The problem comes say for first row I selected Loc 1 and second row is Loc 2 and third row is Loc 1. This is allowed as long the row before and next is not the same. The problem in this scenario I remove the second row then what happens is row 1 is Loc 1 and row 2 is also Loc 2. How to revalidate when I remove a row?
$('table.dynatable tbody tr select[name^="locationFrom"]').live('change', handleLocationFromUpdate);
function handleLocationFromUpdate(index) {
if ($(this).closest('tr').next().length == 0 && $(this).closest('tr').prev().length == 0) {
var nextValue = $('select[name^="locationFrom"]', $(this).closest('tr').next('tr'));
if (nextValue.val() == $(this).val()) $(this).val('');
}
else if ($(this).closest('tr').next().length == 0 && $(this).closest('tr').prev().length > 0) {
//alert("Last Field");
var prevValue = $('select[name^="locationFrom"]', $(this).closest('tr').prev('tr'));
if (prevValue.val() == $(this).val()) $(this).val('');
}
else {
var prevValue = $('select[name^="locationFrom"]', $(this).closest('tr').prev('tr'));
var nextValue = $('select[name^="locationFrom"]', $(this).closest('tr').next('tr'));
if (prevValue.val() == $(this).val() || nextValue.val() == $(this).val()) $(this).val('');
}
}