Recent Posts

Responsive Ads Here

Saturday, 19 December 2015

validate check boxes using java script and jquery



Here you can know about how to validate check boxes using jquery.When we select check box ,then it enable text fields with appropriate values ,if  we make it as un select  ,then it must be disable all text fields ....


<!DOCTYPE html>
<html>
<body>
<form id="formid"> 
<input type="text" id="id1" />
<input type="text" id="id2"  />
<input type="text" id="id3"  />
<input type="checkbox"  id="check" onclick="clickFun()">
<button type="submit" id="but">Submit</button></form>


<script>
$(document).ready(function()
{      
       $("#id1").hide();
        $("#id2").hide();
        $("#id3").hide();
$("#check").click(function()
{
     if($("#check").prop("checked"))
     {
        $("#id1").show();
        $("#id2").show();
        $("#id3").show();
        $("#id1").attr("required","required");
        $("#id2").attr("required","required");
        $("#id3").attr("required","required");
      }
    else
     {
        $("#id1").hide();
        $("#id2").hide();
        $("#id3").hide();
         $("#id1").removeAttr('required');
  $("#id2").removeAttr('required');
  $("#id3").removeAttr('required');
      }
    });
   });
</script>
</body>
</html>

No comments:

Post a Comment