javascript - How to show set of Radio buttons based on a previous Radio Button -
i have form radio buttons on it. when user selects "unfit", want them go on indicate reason second set of radio buttons. don't want reasons displayed until have clicked on "unfit" radio button.
how accomplish in javascript or jquery?
here's code, sorry design
<div class="col-xs-7"> <input type="radio" name="res" <?php if (isset($res) && $res=="fit") echo "checked";?> value="fit">fit <br> <input type="radio" name="res" <?php if (isset($res) && $res=="unfit") echo "checked";?> value="unfit">unfit <br> <input type="radio" name="res" <?php if (isset($res) && $res=="all") echo "checked";?>value="all">all </div> <div class="col-xs-3"> </div> </div> <div class="col-lg-6"> </div> </div> <h4>reason being unfit</h4> <hr> <div class="row"> <div class="col-lg-6"> <div class="col-xs-2"> </div> <div class="col-xs-7"> <input type="radio" name="ru" <?php if (isset($ru) && $ru=="tuberculosis") echo "checked";?> value="tuberculosis">tuberculosis br> <input type="radio" name="ru" <?php if (isset($ru) && $ru=="pneumonia") echo "checked";?> value="pneumonia">pneumonia <br> <input type="radio" name="ru" <?php if (isset($ru) && $ru=="all") echo "checked";?>value="all">all </div> <div class="col-xs-3"> </div> </div> <div class="col-lg-6"> </div> </div>
try below,
you can archive listing click event of each radio button finding id of particular radio box, , checking whether equal radio-unfit..then depend on show next radio button set.
$(document).ready(function() { $("#unfit-reason").hide(); // when click radio check whether radio-unfit $("input[name=res]").click(function() { if ($(this).attr("id") == "radio-unfit") { $("#unfit-reason").show(); } else { $("#unfit-reason").hide(); } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="col-xs-7"> <input type="radio" name="res" <?php if (isset($res) && $res=="fit" ) echo "checked";?>value="fit">fit <br> <input id="radio-unfit" type="radio" name="res" <?php if (isset($res) && $res=="unfit" ) echo "checked";?>value="unfit">unfit <br> <input type="radio" name="res" <?php if (isset($res) && $res=="all" ) echo "checked";?>value="all">all </div> <div class="col-xs-3"> </div> </div> <div class="col-lg-6"> </div> </div> <div id='unfit-reason'> <h4>reason being unfit</h4> <hr> <div class="row"> <div class="col-lg-6"> <div class="col-xs-2"> </div> <div class="col-xs-7"> <input type="radio" name="ru" <?php if (isset($ru) && $ru=="tuberculosis" ) echo "checked";?>value="tuberculosis">tuberculosis br> <input type="radio" name="ru" <?php if (isset($ru) && $ru=="pneumonia" ) echo "checked";?>value="pneumonia">pneumonia <br> <input type="radio" name="ru" <?php if (isset($ru) && $ru=="all" ) echo "checked";?>value="all">all </div> <div class="col-xs-3"> </div> </div> <div class="col-lg-6"> </div> </div> </div>
Comments
Post a Comment