1

I have dynamic table as shown .

Image of the table

How can restrict the rows have same values in both the columns using jquery or javascript

thanks in advance

1
  • Currently I am using this javascript function Commented Feb 3, 2011 at 9:59

1 Answer 1

2

Update: Haim pointed out in the comments that I might have misinterpreted what you were after. So I'll present two options.

If you want to prevent the same values being selected:

$('table').delegate('select', 'change', function () {
    var other = $(this).closest('tr').find('select').not(this);
    if (other.val() == $(this).val()) {
        // Bad! Now what do you want to do?

        // Select nothing?
        this.selectedIndex = -1;
        // Make the row red?
        $(this).closest('tr').css('background-color', 'red');
        // Be reallllly annoying?
        alert('You have made a bad choice!');
    }
});

If you want to keep the two columns the same:

$('table').delegate('select', 'change', function () {
    $(this).closest('tr').find('select').not(this).val($(this).val());
});

See demo: http://jsfiddle.net/yGSNN/

Sign up to request clarification or add additional context in comments.

6 Comments

i think he want to prevent this situation , not to have duplicate values, in your example you make this 2 select box same
@Haim, oh, that sounds very logical now that you mention it. Did not get that sense at all from the question though.
Yes I Want to restrict duplicates
@Tech, see the first part of my answer then ;)
Box9, Thanks for the code. This code restrict in the next consecutive cell, what about to compare the entire table rows for any duplicates ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.