title: cant use javascript to run html radio button
body: <p>I have  this script in my &lt; head > :</p>
  
  <pre><code>&lt;script&gt;
  var rad = document.getElementsByName('search_type');
  alert(rad[1]);
  var prev = null;
  for (var i = 0; i &lt; rad.length; i++) {
      rad[i].onclick = function() {
          (prev)? console.log(prev.value):null;
          if(this !== prev) {
              prev = this;
          }
          console.log(this.value)
          alert(this.value);
      };
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>and this is my form:  </p>
  
  <pre><code>&lt;form name="search_form" action="&lt;?php echo $_SERVER['PHP_SELF']?&gt;" method="post"&gt; 
      &lt;table border="0"&gt; 
          &lt;tr&gt;
              &lt;td class="input"&gt;
                  &lt;input type="radio" name="search_type" value="search_code" checked&gt;1st type&lt;br&gt;
                  &lt;input type="radio" name="search_type" value="search_title"&gt;2nd type&lt;br&gt;
                  &lt;input type="radio" name="search_type" value="search_filter"&gt;3rd type&lt;br&gt;
              &lt;/td&gt;
          &lt;tr/&gt;
      &lt;/table&gt; 
  &lt;/form&gt;
  </code></pre>
  
  <p>but none of alerts work. I have no error in console.  please help.</p>