Skip to content Skip to sidebar Skip to footer

Enabling Inactive Fields By Clicking On Field

Is it possible to have a group of inactive fields where if one of the fields is clicked some of the fields become mandatory and some segments of code are run? Say for example you h

Solution 1:

This method you are looking is called 'chained-select' method.

jQuery framework is used for example below:

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<form action="" method="get">
    <label>
    <input name="Government" type="checkbox" value="">Government</label>
    <br>
    <label>
    <input name="Parent" type="checkbox" id="parent_child_group" value="">Parent</label>
    <br>
    <label>Name of Child
    <input type="text" name="parent_child" value="" class="parent_child_group"></label>
    <br>
    <label>Other
    <input type="text" name="parent_other" value="" class="parent_child_group"></label>
</form>

<script type="text/javascript">
    $(document).ready(function () {
         $(function() {
             enable_cb();
             $("#parent_child_group").click(enable_cb);
         });

         function enable_cb() {
             if (this.checked) {
                 $("input.parent_child_group").removeAttr("disabled");
             } else {
                 $("input.parent_child_group").attr("disabled", true);
             }
         }
    });        
    </script>
    </body>
    </html>

Working example on JSFiddle: http://jsfiddle.net/farondomenic/fg7p8/1/


Post a Comment for "Enabling Inactive Fields By Clicking On Field"