jeudi 25 janvier 2018

control radio button using checkbox?

I want to control radio button using checkbox.I have one checkbox as parent and four radio buttons as child.If i clicked on checkbox then dynamically check 4th radio button along with display layer,also i can check another radio buttons with display layers and if i unchecked the checkbox then uncheck radio button which is checked,disable layers.This works like layer switcher in open layers 3.

I have done little bit code but after i checked checkbox then dynamically 4th radio button with layer is display,remaining radio button cannot switch to other radio buttons.

  $('#builtup input').change(function(){
      var layer=$(this).val();//all radiobuttons value
      var cRad=$("#ck");//checkbox id
     builtup.forEach(function(e){ //builtup array contains four layers builtup[1975,1990,2000,2014]
      var n=e.get('name');
      if(cRad.is(':checked'))
      {
        if(n==2014) //fourth radio button value=2014
        {
           $('#bb4').attr('checked',true); //fourth radio button is checked
           e.setVisible(n==2014);  //visible fourth layer
        }
         if(n==layer) //for switching between othe radio
          {

            $('input[type="radio"]').attr('checked',true);
            e.setVisible(n==layer);

          }
        } 
        else  //uncheck all radio and disable layers
        {
           $('input[type="radio"]').attr('checked',false);
            e.setVisible(false);
        } 

Thanks.




Aucun commentaire:

Enregistrer un commentaire