0

Here i am having two fields

  1. Property Type
  2. Bedroom

Suppose i am i am clicking Property Type is Plot/Site/Land i want to make uncheck for Bedroom, how can do this?

Property Type :

<fieldset class="checkboxes">
        <label><input type="checkbox" name="propertyType" value="4" onclick="myFunction()"> Apartment</label>

         <label><input type="checkbox" name="propertyType" value="5" onclick="myFunction()"> Independent House/ Villa</label>

         <label><input type="checkbox" name="propertyType" value="6" onclick="myFunction()"> Individual House/ Standalone Building</label>

         <label><input type="checkbox" name="propertyType" value="7" onclick="myFunction()"> Plot/Site/Land</label>
</fieldset>


Bedroom:

<ul style="padding-left: 0px;">
          
      <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="1 Room/Hall" name="unitType" type="checkbox" onclick="myFunction()">1 Room/Hall</label></li>
      
          
      <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="1 RK" name="unitType" type="checkbox" onclick="myFunction()">1 RK</label></li>
      
          
      <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="1 BHK" name="unitType" type="checkbox" onclick="myFunction()">1 BHK</label></li>
      
          
      <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="2 BHK" name="unitType" type="checkbox" onclick="myFunction()">2 BHK</label></li>
      
          
      <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="3 BHK" name="unitType" type="checkbox" onclick="myFunction()">3 BHK</label></li>
      
          
      <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="4 BHK" name="unitType" type="checkbox" onclick="myFunction()">4 BHK</label></li>
      
          
      <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="4+ BHK" name="unitType" type="checkbox" onclick="myFunction()">4+ BHK</label></li>
      
          
  </ul>
Mithun M
  • 117
  • 2
  • 11

1 Answers1

3

Register a change() listener on your property type checkbox and uncheck all the unit types.

$(function() {
  $("input[name=propertyType]").change(function() {
    $("input[name=unitType]").prop("checked", false);
  });
});

function myFunction() {
  console.log('myfunction called');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Property Type :

<fieldset class="checkboxes">
  <label><input type="checkbox" name="propertyType" value="4" onclick="myFunction()"> Apartment</label>

  <label><input type="checkbox" name="propertyType" value="5" onclick="myFunction()"> Independent House/ Villa</label>

  <label><input type="checkbox" name="propertyType" value="6" onclick="myFunction()"> Individual House/ Standalone Building</label>

  <label><input type="checkbox" name="propertyType" value="7" onclick="myFunction()"> Plot/Site/Land</label>
</fieldset>


Bedroom:

<ul style="padding-left: 0px;">

  <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="1 Room/Hall" name="unitType" type="checkbox" onclick="myFunction()">1 Room/Hall</label></li>


  <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="1 RK" name="unitType" type="checkbox" onclick="myFunction()">1 RK</label></li>


  <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="1 BHK" name="unitType" type="checkbox" onclick="myFunction()">1 BHK</label></li>


  <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="2 BHK" name="unitType" type="checkbox" onclick="myFunction()">2 BHK</label></li>


  <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="3 BHK" name="unitType" type="checkbox" onclick="myFunction()">3 BHK</label></li>


  <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="4 BHK" name="unitType" type="checkbox" onclick="myFunction()">4 BHK</label></li>


  <li class="col-md-12" style="padding-left: 0px;"><label class="space"><input value="4+ BHK" name="unitType" type="checkbox" onclick="myFunction()">4+ BHK</label></li>


</ul>
31piy
  • 23,323
  • 6
  • 47
  • 67
  • This is not exact answer , suppose i am clicking Plot/Site/Land means i have to uncheck as well i want to make it disable the betroom field it self, when i am uncheck the Plot/Site/Land means again i have to make it enable – Mithun M Nov 28 '17 at 10:58
  • @31piy.are you there? can you please update your answer – Mithun M Nov 28 '17 at 11:02
  • @MithunM -- your question has been marked as duplicate. Also, your question doesn't contain all the requirements. If you believe that your question is different, edit your question, and include all the relevant details. – 31piy Nov 28 '17 at 11:10