开发者

How do you use checkboxes within a radio-button option?

I want to have two radio options. Basically one that says "No" and another that says "Yes", and below the Yes one, I want to have about 3 checkboxes. I want "No开发者_运维问答" to be selected by default, but if any of the checkboxes under "Yes" are clicked, it should switch from "No" to "Yes".


A small javascript function can handle it for you. Then you call the function when a checkbox is ticked or a radio button is selected.

Check out

http://www.javascriptkit.com/javatutors/radiocheck.shtml

This is similar but with buttons http://www.somacon.com/p143.php


This is using jquery

$(document).ready(function(){
   $('.yesbox').click(function () {
   var x = $('.yesbox:checked').length;
      if (x > 0){
      $('#yn2').attr('checked', 'checked');
      $('#yn1').attr('disabled', true);
      }
   });

 $('body').click(function () {
    var x = $('.yesbox:checked').length;
     if (x == 0){
     $('#yn1').attr('disabled', false);
     }
   });

});

And html would go like this:

       <input type='radio' id='yn1' name='yn' value='No'> No<br>
       <input type='radio' id='yn2' name='yn' value='Yes'> Yes  &nbsp; &nbsp;
       <input type = 'checkbox' name='check1' id='check1' class='yesbox' value = '1'> 1
       <input type = 'checkbox' name='check2' id='check2' class='yesbox' value = '2'> 2
       <input type = 'checkbox' name='check3' id='check3' class='yesbox' value = '3'> 3
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜