Conditioned Radio Box

silgreg 18 Aug, 2013
Hi.

I'm new.
My name's Silvano

I need to build a form with two Radio Box.
In the first one users must choose an option (their preferred day-off)
In the second one (which offers the same options of the first one) users must choose an alternative day-off (a second choice different from the options chosen in the first Radio Box).
Is it possibile to prevent users from choosing the same day-off twice? Maybe through a special code?

Thanks. Silvano
GreyHead 18 Aug, 2013
Hi Silvano,

You can do that with a little JavaScript to disable the day selected in the first radio button group in the second group.

Here's an example that seems to work OK.
window.addEvent('domready', function(){
  var choices_1, choices_2;
  choices_1 = $$('[name=choice_1]');
  choices_2 = $$('[name=choice_2]');
  choices_1.each(function(el) {
    el.addEvent('click', function(event){
      el1 = event.target;
      choices_2.each(function(el2){
        if ( el1.value == el2.value ){
          el2.checked = false;
          el2.disabled = true;
        } else {
          el2.disabled = false;
        }
      });
    });
  });
});
Note that here 'choice_1' and 'choice_2' are the names of the two radio box groups and the values of the options in the two groups are the same.

Bob
silgreg 18 Aug, 2013
Fantastic.
The script works perfectly.
Thank you for your kindness.
Silvano
This topic is locked and no more replies can be posted.