views:

60

answers:

3

I am building a form to rank series of items. The user will read the item and select in a dropdown the rating from 1 to 20. All 20 items will be displayed at the same time. What is the best way to make sure that the user didn't select the same number for more than one choice? Then I would display an error message, "You've already ranked an item as number 5"

Thanks

+2  A: 

Put the items in a list with options to move an element up or down in the list.

Mark Byers
Perfect fit for this question, it's kind of why this method exists.
chelmertz
and use drag and drop javascript (ajax) to make it totally user friendly.
allesklar
@allesklar. Indeed. For example: http://tool-man.org/examples/sorting.html
Mark Byers
A: 

There is a jquery plug-in for validation, that can help you define rules. It only works on submit, though but it'll still wont send the form and tell you which entry is wrong. Take a look at it, may be it can help you.

stefita
+1  A: 

I would suggest something like the following function. You may want to add something to revert the selection to some default value if it is a duplicate.

function checkDupe(element) {
    var dupe = false;

    $("select").each(function() {
    if ($(this).attr("id") != $(element).attr("id") && $(this).attr("value") == $(element).attr("value")) {
            dupe = true;

            alert("You have already ranked an item number " + $(element).attr("value"));

            return;
        }
    });

    return dupe;
}

Just add that to the onchange event for all the dropdown lists like this.

<select id="a1" onchange="checkDupe(this)">

It's important to note that each list must have a unique ID.

Nikolas Stephan