javascript - Enabling inactive fields by clicking on field -
is possible have group of inactive fields if 1 of fields clicked of fields become mandatory , segments of code run? example have 3 fields shown:
<input type="text" id="gov1" name="gov1"> <input type="text" id="parentb" name="parentb"> <input type="checkbox" name="child" id="child">
all 3 of these fields inactive; click on 1 of fields makes rest active , mandatory, , segment of code run on field "parentb" , attributed @ readonly.
window.onload = function(event) { var $input2 = document.getelementbyid('dec'); var $input1 = document.getelementbyid('parentb'); $input1.addeventlistener('keyup', function() { $input2.value = $input1.value; }); }
i have done bit of searching around can't seem find of use specific situation , i'm quite new javascript sort of great. @ possible using javascript? or similar possible?
this method looking called 'chained-select' method.
jquery framework used 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/
Comments
Post a Comment