jeudi 28 décembre 2017

Checkboxes How can i check to sets at same time

I have 2 sets of checkboxes in my webpage, and i have a small script that is checking the boxes and not the others when i click one, Which is what i want it to do.

unfortunatly it only checks one set of the boxes. and leaves the other set unchecked..

Allthough on reloading my page. both sets are checked , but this is due to my post veriable.. i will show you the code..

can anybody see where i could update it to check both boxes on clicking one box.. thank you.

<div id='checkbox-container'>

    <input type="checkbox" id="small" name="displaytypethumbs"  value="minlist" <?php if (!empty($_POST['displaytypethumbs'])): ?> checked="checked"<?php endif; ?> onclick="chbx(this)">
    <label for="small" class="smalllistings">Thumbs</label>
    </input>

    <input type="checkbox" id="large"  name="displaytypegallery"  value="maxlist" <?php if (!empty($_POST['displaytypegallery'])): ?> checked="checked"<?php endif; ?> onclick="chbx(this)">
    <label for="large" class="largelistings" >Gallery</label>   
    </input>

    <input type="checkbox" id="fulllistings"  name="displaytypefull"  value="fulllist" <?php if (!empty($_POST['displaytypefull'])): ?> checked="checked"<?php endif; ?>onclick="chbx(this)">
    <label for="fulllistings" class="fulllistings" >Full Listing</label>    
    </input>

</div>

<div id='checkbox-container2'>

<input type="checkbox" id="small2" name="displaytypethumbs"  value="minlist"  class="smalllistingsbox" 
<?php if (!empty($_POST['displaytypethumbs'])): ?> checked="checked"<?php endif; ?> onclick="chbx(this)">
<label for="small2" class="smalllistingsmain" >Thumbs</label>
</input>


<input type="checkbox" id="large2"  name="displaytypegallery"  value="maxlist" class="largelistingsbox"  
<?php if (!empty($_POST['displaytypegallery'])): ?> checked="checked"<?php endif; ?> onclick="chbx(this)">
<label for="large2" class="largelistingsmain" >Gallery</label>  
</input>


<input type="checkbox" id="fulllistings2"  name="displaytypefull"  value="fulllist" 
<?php if (!empty($_POST['displaytypefull'])): ?> checked="checked"<?php endif; ?> onclick="chbx(this)">   
<label for="fulllistings2" class="fulllistingsmain"  >Full Listings</label> 
   </input>


</div>

</form>

<script>
function chbx(obj)
{
   var that = obj;
   if(document.getElementById(that.id).checked == true)
  {
   document.getElementById('small').checked = false;
   document.getElementById('large').checked = false;
   document.getElementById('fulllistings').checked = false;


   document.getElementById('small2').checked = false;
   document.getElementById('large2').checked = false;
   document.getElementById('fulllistings2').checked = false;      

   document.getElementById(that.id).checked = true;
  }
}

</script>




Aucun commentaire:

Enregistrer un commentaire