# Multiple Radio Groups - allow only unique on each row and only allow 5 choices max

I need to create a form with multiple rows of radio groups

the choice/values for each row/group is 1,2,3,4,5

I need to make sure only one of each value is selected (i.e. so the visitor can't choose the same value twice in different rows) and that only five rows max can be selected.

I was trying to do it by:
- function on change of radio
- get the values of all and create an array
- see if there are duplicates in the array and alert to inform that different values must be chosen
- count the choices and alert if more than five.

here's the table test code I've been playing around with:
http://jsfiddle.net/3uxZY/26/

many thanks
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
So basically all you need is to make sure that only 5 choices are made where they do not select 'Not Chosen' and that there is 1 of each value 1 through 5
0
Commented:
Obvious answer would be sum the values and if it is > 15 then its not valid
0
Author Commented:
I did think that myself at first, but then that would allow duplicates to be selected - I was hoping I might be able to check for duplicates as they were selected
0
Author Commented:
Your first reply is correct as to what I'm trying to achieve. If I could alert when duplicate is selected that would be good.
0
Commented:
So would something like this work
http://jsfiddle.net/GaryC123/3uxZY/29/

(I amended your radio to set a value of 0 for no choice, and fixed the double 4's)

``````\$(document).ready(function () {
\$("#t").click(function(e){
score=0

score+=parseInt(\$(this).val());
})
if(score!=0 &&
score!=1 &&
score!=3 &&
score!=6 &&
score!=10 &&
score!=15){
e.preventDefault()
}
else{
e.preventDefault()
}
})
});
``````

I wouldn't check for duplicates as they click, people make changes as they go and alerting them to fact or disabling the choice would be annoying
0
Author Commented:
That's a big improvement but you can still choose: 2, 2, 5, 5, 1 for example (totals 15) but I really need to make sure there aren't any duplicate numbers (so we can get their first, second, third, fourth and fifth choices)

many thanks
0
Author Commented:
good point about alerting as they click - on submit is better

thanks
0
Commented:
This is a bit messy and can probably be cleaned up
http://jsfiddle.net/GaryC123/3uxZY/31/
0
Commented:
0
Author Commented:
That's brilliant - thanks for that - I could just do with checking that 5 have been checked or that they add up to 15.
Would it be possible to incorporate a count number of checks into this maybe (or just get the values and add to equal 15 as before)

cheers
0
Commented:
Not sure I understand you.
Only 5 (or less) can be selected else you get an error
You cannot select the same value twice.
0
Author Commented:
I think you can select for example: 1,2,3,4

(without a 5th) - otherwise it's perfect..

thanks
0
Commented:
I thought you allowed less than 5 to be selected?
0
Commented:
Updated to make sure 5 are selected
http://jsfiddle.net/GaryC123/3uxZY/36/
0

Experts Exchange Solution brought to you by