mercredi 5 juin 2019

why isn't 2nd IF statement read?

The second IF statement is not reached/read.

I switched order of the two IF statements; only the first produces a result. I put semicolons various places, but now I understand they are optional. I removed the line space.

<!DOCTYPE html>
<html>
<body>

<input type="radio" name="region" id="state">State <br>
<input type="radio" name="region" id="county">county <br>
<input type="radio" name="region" id="country">country <br>
<br><br>
<input type="radio" name="timerange" id="range30">30 years<br>
<input type="radio" name="timerange" id="range50">50 years<br>
<input type="radio" name="timerange" id="range100">100 years<br>

<button onclick="myChoices()">my selections are made</button>

<script>

  function myChoices() {
   if (document.getElementById("state").checked) 
      {document.write("state")}
   else if (document.getElementById("county").checked) 
      {document.write("county")}
   else {document.write("country")}   

   if (document.getElementById("range30").checked) 
      {document.write("30yrs")}
   else if (document.getElementById("range50").checked) 
      {document.write("50 yrs")}
   else {document.write("100yrs")}   
  }  
</script>

</body>
</html>

I select one choice from each set of radio buttons and click the button. Only the result from the first IF is returned. Thanks in advance for helping this self-taught beginner! Note: I understand this code may not be efficient; in any case I would like to know why it doesn't work. Thanks

Aucun commentaire:

Enregistrer un commentaire