lundi 22 mai 2017

select checkbox the statement or text will appear in html

why my coding doesn't work? I want it like this; if select checkbox the statement or text will appear based on if else or swith. can u fix my coding? whats wrong with my coding? Here's my code:

<script type="text/javascript">
  function ShowHideDiv(Fish) {
    var subAnimal = document.getElementById("subFish");
    subFish.style.display = Fish.checked ? "block" : "none";
    console.log(Fish.value)
    console.log("Text Inside LABEL:" + Fish.parentNode.textContent)
  }
</script>

<label for="Fish">
    <input type="checkbox" id="Fish" onclick="ShowHideDiv(this)" value="Fish"/> Fish 
</label>

<div id="subFish" style="display: none">

  <label> 
    <input type="checkbox" id="subFish1" /> Tank 
</label>

  <label> 
    <p id="subFishs1" ></p> 
</label>

  <label>
        <input type="checkbox" id="subFish2" /> Fishing 
</label>

  <label> 
    <p id="subFishs2" ></p> 
</label>

  <script>
    function ShowHideDiv2(this) {

      var a = document.getElementById("subAnimal1").checked;
      var b = document.getElementById("subAnimal2").checked;

      if (a && b) {
        document.getElementById("subAnimal1").addEventListener("click", function() {
              document.getElementById("subAnimals1").innerHTML = "Bad";
            } else if (a && !b) {
              document.getElementById("subAnimal2").addEventListener("click", function() {
                  document.getElementById("subAnimals2").innerHTML = "Cute";
                } else {
                  alert("Under Development!");
                }
              }
  </script>



Aucun commentaire:

Enregistrer un commentaire