title: how to figure out which radio button was selected using jsp
body: <p>i have two radiobuttons in my application, one is meterid with with combobox and another is consumername with textbox . now the problem is whenever i am selecting the radio button the result is coming correct only but i am unable to findout that which radio button i have selected.</p>
  
  <pre><code>My application includes the following code:
  
  
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@page import="java.sql.*"%&gt;
  &lt;%@ page import="java.text.SimpleDateFormat"%&gt;
  &lt;%
  Connection con;
  String sqlQuery="";
  Statement st;
  ResultSet rs=null;
  %&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Meter Search
  &lt;/title&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;link rel="stylesheet" href="styles.css" type="text/css" media="screen" /&gt;
  
  
  &lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;
  
  &lt;style&gt;
  td{FONT: 13px Arial,sans-serif;}
  th{FONT:bold 13px Arial,sans-serif;color:white;background-color:#153e7e}
  input{FONT: 13px Arial,sans-serif;border: solid 1;}
  select{font: 13px Arial,sans-serif}
  #button{cursor:hand}
  A:hover {COLOR: red}&lt;/style&gt;
  
  
  
  
  &lt;/head&gt;
  
  &lt;body onload ="noback();" onpageshow="if (event.persisted) noBack();" onunload=""&gt;
  
  &lt;br&gt;&lt;br&gt;
  
  &lt;form action="./metersearchsuper.jsp" method="post" name="search"&gt;
  &lt;table align="left" width="40%" border="0" cellpadding="5" cellspacing="1" bgcolor="#f8f8ff" bordercolor="#333366" &gt;
    &lt;tbody&gt;&lt;tr&gt;
      &lt;th colspan="6"  width ="40%" &gt;Search options&lt;/th&gt;&lt;/tr&gt;
  
  
  
  &lt;tr&gt;&lt;td  width="15%" class="options0" id="tdSearchBy" colspan="5"&gt;
  
  &lt;input name="r1" value="MeterID" onclick="searchOptions(0)" type="radio"&gt;&lt;font size="4"&gt;Meter ID&lt;/font&gt;&lt;/td&gt;
  
  &lt;%
      Class.forName("com.mysql.jdbc.Driver");
      con = DriverManager.getConnection("jdbc:mysql://localhost:3306/suwatermeter","root","sumith");
      sqlQuery="select distinct Meterid from Meter_List";
      st=con.createStatement();
  
       rs=st.executeQuery(sqlQuery);
  %&gt;
  
  
  &lt;td  width="20%" class="options0" colspan="5"&gt;&lt;select style="WIDTH: 150px" selected="true" name="meterid" id="meter_id" onChange="this.form.submit()"&gt;
  &lt;option&gt;Select Meter ID&lt;/option&gt;
  &lt;% while(rs.next()) {%&gt;
  &lt;option value="&lt;%=rs.getInt("MeterID")%&gt;"&gt;&lt;%=rs.getInt("MeterID")%&gt;&lt;/option&gt;
  
  &lt;% } 
  
  rs.close();
  st.close();
  con.close();
  %&gt;
  
  &lt;/select&gt;
  
  &lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;&lt;td class="options1" id="tdSearchBy" colspan="5"&gt;
  
  &lt;input name="r1" value="ConsumerName"  onclick="searchOptions(1)" type="radio"&gt;&lt;font size="3"&gt;Consumer Name&lt;/font&gt;
  &lt;/td&gt;
  &lt;td&gt;&lt;input name="cnsearch" style="WIDTH: 150px"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;table&gt;
  &lt;tbody&gt; 
  &lt;tr&gt;&lt;td style="height: 50px; border: 1px solid rgb(255, 255, 255);" colspan="4" align="center"&gt;
  
  &lt;input name="bSearch" value="Search" style="width: 80px; HEIGHT: 34px; border: 1px solid rgb(13, 31, 78);" onclick="return checkInput()" type="submit"&gt;
  
  &lt;/td&gt;&lt;/tr&gt;
  
  
    &lt;/tbody&gt;&lt;/table&gt;
  
  &lt;%
  
  try{
  
  
      String meterid =request.getParameter("meterid");
  
      String cnsearch=request.getParameter("cnsearch");
      String r1=request.getParameter("r1");
      String flag="";
      int mid;
  
      String ConsumerName;
  
      int SNo=1;
  
      Class.forName("com.mysql.jdbc.Driver");
      con = DriverManager.getConnection("jdbc:mysql://localhost:3306/suwatermeter","root","sumith");
      st=con.createStatement();
     %&gt;
      &lt;input type="hidden" id="Hmeter_id" value="&lt;%=meterid%&gt;"&gt;
  
  
  &lt;%
  
  if(r1.equals("MeterID"))
  {
      rs=st.executeQuery("select * from Meter_List where Meterid="+meterid);
      flag="false";
  }
  
  if(r1.equals("ConsumerName"))
  {
      rs=st.executeQuery("select * from Meter_List where Consumername='"+cnsearch+"'");
      flag="false";
  }
  if(flag.equals("false"))
  {%&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
  
   &lt;table width="100%" height="20%"&gt;
  
   &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
  
  &lt;%
  boolean mycolor=true;
  int tHeading=0;  //0 means false
  
  if(meterid != null &amp;&amp; cnsearch != null )
  
      tHeading=0;
  
  //else if(getZoneName !=null || !getZoneName.equals("") || !getZoneName.isEmpty())
  
    // { 
      //tHeading=1;
    // }
  
  while(rs.next()){
  String checkdate="";
  SimpleDateFormat df=new SimpleDateFormat("dd-MM-yy");
  checkdate=df.format(rs.getDate("Date"));
  
  if(tHeading==0)
      {%&gt;
          &lt;table  border="0" style="" width="100%" align="center" cellpadding="5" cellspacing="0"&gt;
          &lt;tbody&gt;
          &lt;th&gt;S No&lt;/th&gt;
          &lt;th&gt;Meter ID&lt;/th&gt;
          &lt;th&gt;Consumer ID&lt;/th&gt;
          &lt;th&gt;Consumer Name&lt;/th&gt;
          &lt;th&gt;Reading&lt;/th&gt;
          &lt;th&gt;Date&lt;/th&gt;
          &lt;th&gt;Time&lt;/th&gt;
          &lt;th&gt;Status&lt;/th&gt;
          &lt;th&gt;Sub Zone&lt;/th&gt;
          &lt;th&gt;Zone&lt;/th&gt;
                  &lt;%tHeading=1;
  
        }
  
   if(mycolor==true)
   {%&gt;
          &lt;tr&gt;
      &lt;td align="center" bgcolor="#ffffff"&gt;&lt;%=SNo%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ffffff"&gt;&lt;a href="meteridinfosuper.jsp?mid=&lt;%=rs.getInt("meterid")%&gt;
  &amp;Consumerid=&lt;%=rs.getInt("Consumerid")%&gt;&amp;Consumername=&lt;%=rs.getString("Consumername")%&gt;&amp;Subzone=&lt;%=rs.getString("Subzone")%&gt;&amp;Zone=&lt;%=rs.getString("Zone")%&gt;"&gt;
      &lt;%=rs.getInt("Meterid")%&gt;&lt;/a&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ffffff"&gt;&lt;%=rs.getInt("Consumerid")%&gt;&lt;/td&gt;
      &lt;td  align="center" bgcolor="#ffffff"&gt;&lt;%=rs.getString("Consumername")%&gt;&lt;/td&gt;
      &lt;td  align="center" bgcolor="#ffffff"&gt;&lt;%=rs.getInt("LastReading")%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ffffff"&gt;&lt;%=checkdate%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ffffff"&gt;&lt;%=rs.getTime("Time")%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ffffff"&gt;&lt;%=rs.getString("Status")%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ffffff"&gt;&lt;%=rs.getString("Subzone")%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ffffff"&gt;&lt;%=rs.getString("zone")%&gt;&lt;/td&gt;
          &lt;/tr&gt;&lt;%
          mycolor=false;
  }
  else
  {%&gt;   &lt;!--ceefff--&gt;
      &lt;tr&gt;
      &lt;td align="center" bgcolor="#ceefff"&gt;&lt;%=SNo%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ceefff"&gt;&lt;a href="meteridinfosuper.jsp?mid=&lt;%=rs.getInt("meterid")%&gt;
  &amp;Consumerid=&lt;%=rs.getInt("Consumerid")%&gt;&amp;Consumername=&lt;%=rs.getString("Consumername")%&gt;&amp;Subzone=&lt;%=rs.getString("Subzone")%&gt;&amp;Zone=&lt;%=rs.getString("Zone")%&gt;"&gt;
      &lt;%=rs.getInt("Meterid")%&gt;&lt;/a&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ceefff"&gt;&lt;%=rs.getInt("Consumerid")%&gt;&lt;/td&gt;
      &lt;td  align="center" bgcolor="#ceefff"&gt;&lt;%=rs.getString("Consumername")%&gt;&lt;/td&gt;
      &lt;td  align="center" bgcolor="#ceefff"&gt;&lt;%=rs.getInt("LastReading")%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ceefff"&gt;&lt;%=checkdate%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ceefff"&gt;&lt;%=rs.getTime("Time")%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ceefff"&gt;&lt;%=rs.getString("Status")%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ceefff"&gt;&lt;%=rs.getString("Subzone")%&gt;&lt;/td&gt;
      &lt;td align="center" bgcolor="#ceefff"&gt;&lt;%=rs.getString("zone")%&gt;&lt;/td&gt;
          &lt;/tr&gt;&lt;%     
          mycolor=true;
  }
  
  SNo++;
  }
  
  }
  rs.close();
  st.close();
  con.close();
  } 
  
  catch(Exception e){}
  
  %&gt;
  &lt;script&gt;
  
      document.getElementById("meter_id").value=document.getElementById("Hmeter_id").value;
  &lt;/script&gt;
  
  &lt;/table&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;         
  </code></pre>
  
  <p>please help me to solve this.</p>