title: validating radio buttons
body: <p>I'm processing a form with php and I want to add validation on the client side too. I read about.com's tutorial about validating radio buttons with javascript and set up this sample according to its guidelines. </p>
  
  <p>a) Why isn't it showing the alert message? </p>
  
  <p>b) How can I substitute the alert message for some innerHtml text?  </p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
  &lt;html&gt;&lt;head&gt;
  
  &lt;meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"&gt;&lt;title&gt;validateradio&lt;/title&gt;
  
  
  &lt;script type="text/javascript"&gt;
  
  
  function valButton(btn) {
      var cnt = -1;
      for (var i=btn.length-1; i &gt; -1; i--) {
          if (btn[i].checked) {cnt = i; i = -1;}
      }
      if (cnt &gt; -1)  return btn[cnt].value;
      else          return null;
  
  }
  
  
  
  
  function valButton2(form){
  
  var btn=valButton(form.group1);
  if (btn==null){alert('no radio button selected');}
  else alert('button value' + btn + 'selected');
  
  
  }
  
  
  &lt;/script&gt;
  
  
  &lt;/head&gt;
  
  
  &lt;body style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" alink="#000088" link="#0000ff" vlink="#ff0000"&gt;&lt;br&gt;
  
  &lt;form name="myform"&gt;
  
  
   &lt;label for="r1"&gt;&lt;input type="radio"
  name="group1" id="r1" value="1" /&gt; button one&lt;/label&gt; 
  
   &lt;label for="r2"&gt;&lt;input type="radio"
  name="group1" id="r2" value="2" /&gt; button two&lt;/label&gt;
  
   &lt;label for="r3"&gt;&lt;input type="radio"
  name="group1" id="r3" value="3" /&gt; button three&lt;/label&gt; 
  
  
  &lt;input type="submit" name="submitit" onclick="valbutton2(myform);" value="Validate" /&gt;
  
  
  
  &lt;/form&gt;
  
  
  
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>