0

I have 3 radio groups, and I want to check is the button is selected in each radio group.

For example I want something like that

if (in each radio group one button is selected){
do something 
}

if ( one of RadioGroups have no selected button) {
Show something like Toast 
}
Jeremy
  • 22,188
  • 4
  • 68
  • 81
lukaszgo3
  • 149
  • 3
  • 15

4 Answers4

0

Read the three group by name. Then iterator other it. Check .checked using conditional statement.

var radios = document.getElementsByTagName('input1');
var value;
for (var i = 0; i < radios.length; i++) {
    if (radios[i].type === 'radio' && radios[i].checked) {
       // get value, set checked flag or do whatever you need to
       value = radios[i].value;       
    }
}
0

Suppose you have three radioButtons namely one two and three. You could do like this.

if(one.isChecked() || two.isChecked() || three.isChecked()){

      //do something 


 }else if(!one.isChecked() || !two.isChecked() || !three.isChecked()){
     //do something
                    Toast.makeText(TourClass.this, "Passwords do not match", 
Toast.LENGTH_LONG).show();




  }
Mithun Adhikari
  • 521
  • 6
  • 13
0

Use getCheckedRadioButtonId() for finding the checked RadioButton in the RadioGroup.

Deena
  • 41
  • 3
0

for each RadioGroup you write this:

if (radioGroup.getCheckedRadioButtonId() == -1)
{
  // no radio buttons are checked
}
else
{
  // one of the radio buttons is checked
}

and you can also check answers here How to check if a radiobutton is checked in a radiogroup in Android?

TarekB
  • 757
  • 14
  • 20