javascript - How would I validate unique selects, within nth sub sets of selects? -


i have code generated dynamically.

<p>    class choices 1 </br>    <select name="1_option_1">       <option value=4>2x3 study time</option>       <option value=5>2x3 science time</option>       <option value=6>2x3 math time</option>    </select>    choice 1 </br>    <select name="2_option_1">       <option value=4>2x3 study time</option>       <option value=5>2x3 science time</option>       <option value=6>2x3 math time</option>    </select>    choice 2 </br>    <select name="3_option_1">       <option value=4>2x3 study time</option>       <option value=5>2x3 science time</option>       <option value=6>2x3 math time</option>    </select>    choice 3 </br> </p> <p>    class choices 2 </br>    <select name="1_option_2">       <option value=1>2x3 knitting</option>       <option value=2>2x3 computers</option>       <option value=3>2x3 having fun</option>    </select>    choice 1 </br>    <select name="2_option_2">       <option value=1>2x3 knitting</option>       <option value=2>2x3 computers</option>       <option value=3>2x3 having fun</option>    </select>    choice 2 </br>    <select name="3_option_2">       <option value=1>2x3 knitting</option>       <option value=2>2x3 computers</option>       <option value=3>2x3 having fun</option>    </select>    choice 3 </br> </p> 

the above code follows these rules.

for (nth) class choices (block?)

  • if class choice (block?) has 2 classes, 2 choice option selects generated.
  • if class choice (block?) has 3 classes, 3 choice option selects generated.
  • ...
  • if class choice (block?) has n classes, nth choice option selects generated.

note generated unique select names intention make finding unique sets easier. if not case can change given have more uniformed names. also, can add class names or other properties needed. new html , scripting doing lots of guess work.

no requirements scripting languages.

how validate unique selects, within nth sub sets of selects? is, each choice block, enforce unique values options.

for example:

rejected inputs

class choices 1 != 4,4,4   class choices 1 != 4,4,5   class choices 1 != 4,4,6  ... class choices 1 != 5,5,5   class choices 1 != 5,4,4   class choices 1 != 5,6,6   ... class choices 1 != 6,6,6   class choices 1 != 6,6,5   class choices 1 != 6,4,4   ... 

for duplicates

accepted inputs

class choices 1 == 4,5,6   class choices 1 == 5,6,4   class choices 1 == 6,5,4   ... 

the scope of validation should relate class choice(s). class choice 1, class choice 2, ... class choice n

here's gist solving task.

$(function(){   $('select').change(function(){     var enabled = [];      $('.group').each(function(){       var values = [];       $(this).children('select').each(function(){         var value = $(this).find(":selected").val();         // fills enabled array true or false depending if value unique group;          enabled.push(arewespecialyet(values, value));          values.push(value);       });     });     // enables button if unique.     enablethebutton(enabled);   }); }); 

if you're interested can check working example here, work number of groups or options:

jsbin example


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -