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
freshwaterwestAsked:
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.

GaryCommented:
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
GaryCommented:
Obvious answer would be sum the values and if it is > 15 then its not valid
0
freshwaterwestAuthor 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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

freshwaterwestAuthor 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
GaryCommented:
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

         $("[type=radio]:checked").each(function(){
        score+=parseInt($(this).val());
         })
         if(score!=0 &&
            score!=1 &&
            score!=3 &&
            score!=6 &&
            score!=10 &&
            score!=15){
      alert("Please only choose 5 from 1 to 5")
      e.preventDefault()
         }
        else{
            e.preventDefault()
            alert("It's Ok")
        }
    })
});

Open in new window


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
freshwaterwestAuthor 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
freshwaterwestAuthor Commented:
good point about alerting as they click - on submit is better

thanks
0
GaryCommented:
This is a bit messy and can probably be cleaned up
http://jsfiddle.net/GaryC123/3uxZY/31/
0
GaryCommented:
0
freshwaterwestAuthor 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
GaryCommented:
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
freshwaterwestAuthor Commented:
I think you can select for example: 1,2,3,4

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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
freshwaterwestAuthor Commented:
Perfect - many thanks - I've learnt a few things there : )
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.