title: I have to validate my form for radio buttons using javascript for my code given below
body: <p>i have retrieve questions and answers from the sql table and represented them using this code. now, i have a problem that how to take the radio button name in javascript.
  for every question there must be a one option checked. i have to do this for all questions.</p>
  
  <pre><code>&lt;form action="answer.php?title=&lt;?php echo $_GET['title'];?&gt;" method="post"&gt;
  &lt;table id="myques"&gt; 
  &lt;?php 
  $i=0;
  while($row=mysql_fetch_array($result)){
  ?&gt;     
  &lt;tr&gt;
  &lt;td&gt;&lt;?php echo ++$i.')'; ?&gt;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp&amp;nbsp&amp;nbsp&lt;?php echo $row['question']; ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="radio" name="&lt;?php echo $row['question'];?&gt;" id="ques" value="&lt;?php echo $row['opt1'];?&gt;"&gt;&lt;?php echo $row['opt1']; ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;/td&gt;    
  &lt;td&gt;&lt;input type="radio" name="&lt;?php echo $row['question'];?&gt;" id="ques" value="&lt;?php echo $row['opt2'];?&gt;"&gt;&lt;?php echo $row['opt2']; ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;/td&gt;    
  &lt;td&gt;&lt;input type="radio" name="&lt;?php echo $row['question'];?&gt;" id="ques" value="&lt;?php echo $row['opt3'];?&gt;"&gt;&lt;?php echo $row['opt3']; ?&gt;&lt;/td&gt;
  &lt;/tr&gt; 
  &lt;tr&gt;
  &lt;td&gt;&lt;/td&gt;    
  &lt;td&gt;&lt;input type="radio" name="&lt;?php echo $row['question'];?&gt;" id="ques" value="&lt;?php echo $row['opt4'];?&gt;"&gt;&lt;?php echo $row['opt4']; ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php } ?&gt;       
  &lt;tr&gt;&lt;td colspan="4"&gt;&lt;input type="submit" name="add" onClick="return validate()" /&gt;&lt;/td&gt;&lt;/tr&gt;         
  &lt;/table&gt;
  </code></pre>