Checkbox with JQuery (select and deselect)

0

Good day forum.

I bring you a query about jquery and html, I have a form and in this three checkbox which each one will have a different behavior is to say when you select the first checkbox show me when the deselections I hide that div until the At the moment I have achieved the following:

<script>
 $(document).ready(function(){

 $("#checkbox1").click(function(){
      if(this.checked == true){
        id = $(this).val();
        $.post("index.php?action=getcolor1", {id:id}, function(data){
          $("#result").html(data);
          $("#checkbox2").attr('checked', false);
          $("#checkbox3").attr('checked', false);
        });

      }else if(this.checked == false){
        $("#result").hide();
      }
    });

     $("#checkbox2").click(function(){
      if(this.checked == true){
        id = $(this).val();
        $.post("index.php?action=getcolor2", {id:id}, function(data){
        $("#result").html(data);
        $("#checkbox1").attr('checked', false);
        $("#checkbox3").attr('checked', false);
      });

      }else if(this.checked == false){
        $("#result").hide();
      }
  });

      $("#checkbox3").click(function(){
      if(this.checked == true){

        id = $(this).val();
      $.post("index.php?action=getcolor3", {id:id}, function(data){
        $("#result").html(data);
        $("#checkbox1").attr('checked', false);
         $("#checkbox2").attr('checked', false);

      });

      }else if(this.checked == false){
        $("#result").hide(); 
    }

  });
});    

Even at this moment I can call each one of the elements of each checkbox but at the moment of deselecting it does not remove my.

Someone can mention me some reference. in advance thank you

    
asked by Ever 13.09.2017 в 21:38
source

1 answer

3

Thank you for filling my question, but I already found the solution, just change my $("#result").hide(); to $("#result").empty(); for someone else's help.

    
answered by 13.09.2017 в 22:57