title: Show/hide fieldset based on radio button using Javascript
body: <p>I'm trying to have the email/phone number section of a contact form hidden or visible depending on whether the user picks the phone or email radio button, but I cannot figure out why it is not working for me.
  I've searched through stack overflow &amp; w3Schools, and I'm pretty certain I'm using the correct syntax but it will still not show/hide depending on the radio buttons.
  Any help would be hugely appreciated!</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;form name="contactForm" id="contactForm" method="post" action="result.php"&gt;
                  &lt;fieldset&gt;
                      &lt;!-- Client's contact details --&gt;
                      &lt;legend&gt;Contact Details&lt;/legend&gt;
                          &lt;label for="fullname"&gt;Full Name:&lt;/label&gt;
                          &lt;input type="text" name="contact" id="fullname" required&gt;
  
                          &lt;label&gt;Preferred contact method:&lt;/label&gt;
                          &lt;input type="radio" name="contact" value="rdoPhone" id="rdoPhone" checked="checked" onclick="cPhone()" &gt;Phone
                          &lt;input type="radio" name="contact" value="rdoEmail" id="rdoEmail" onclick="cEmail()" &gt;Email
  
                          &lt;label for="phonenumber"&gt;Phone Number:&lt;/label&gt;
                          &lt;input type="text" name="contact" id="phonenumber"&gt;
                          &lt;label for="email"&gt;Email:&lt;/label&gt;
                          &lt;input type="text" name="contact" id="email"&gt;
                  &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>CSS</p>
  
  <pre><code>#email {
  display:none;
  }       
  #phonenumber {
      display:none;
  }
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>function cPhone() {
  if (document.getElementById("rdoPhone").checked)
  { document.getElementById("phonenumber").style.display = "block"; }
  }
  
  function cEmail(){
  if (document.getElementById("rdoEmail").checked)
  { document.getElementById("email").style.display = "block"; }
  }
  </code></pre>