function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IZavalunIZavalun 

Syntax Error getting value from the radio button

Please help me to figure out how to get value for checked radio, I am getting message:syntax error
========================================================
 
<html>
<head>
<script language="javascript" src="/soap/ajax/9.0/connection.js"></script>
<script language="javascript">
<!--
function do_code() {
r1=document.getElementById("radio").elements[0].value;
r2=document.getElementById("radio").elements[1].value;
alert(r1);
alert(r2);

}
//-->
</script>

<table border="0" width="100%">
<tr>
<td align="center">Primary Distributor<input id="radio" name="radio" type="radio" value="pd"  /> </td>
<td>Secondary Distributor<input id="radio" name="radio" type="radio" value="sd" /> </td>
</tr>
<hr>
<tr>
 <td>
    <input type="button" name="btnSearch" value="Search" id="btnSearch" onclick="do_code()">
 </td>
</tr>
</table>
</html>
</body>
DevAngelDevAngel
I believe you want  ("radio").elements[0].checked;
HarmpieHarmpie
Code:
<html>
<head>
<script language="javascript" src="/soap/ajax/9.0/connection.js"></script>
<script language="javascript">
<!--
function do_code() {
 var radioOptions = document.getElementsByName('radio');
 for(x=0;x<radioOptions.length;x++) {
  if(radioOptions[x].checked) {
   alert(radioOptions[x].value);
  }
 }

}
//--> 
</script> 

<table border="0" width="100%">
<tr>
<td align="center">Primary Distributor<input id="radio" name="radio" type="radio" value="pd"  /> </td>
<td>Secondary Distributor<input id="radio" name="radio" type="radio" value="sd" /> </td>
</tr>
<hr>
<tr>
 <td>
    <input type="button" name="btnSearch" value="Search" id="btnSearch" onclick="do_code()"> 
 </td>
</tr>
</table>
</html>
</body>

 
HarmpieHarmpie
You shouldn't give radio options the same id. You best query em by name