I have two drop down lists with the names meterid and subzone and also i have 2 radio buttons in my application.If the user selects radio button1 , meterid dropdown list should be displayed. If the user selects radio button2, subzone dropdown list should be displayed. i will get the dropdown values from mysql tables.
i tried the following code:
function select1()
{ document.getElementById("meter_id").style.display="block"; document.getElementById("subzone_list").style.display="none"; }
function select2() {
document.getElementById("subzone_list").style.display="block";
document.getElementById("meter_id").style.display="none";
}
document.getElementById("midradio").onclick = select1;
document.getElementById("subzonerd").onclick = select2;
</script>
The following code is for Meterid dropdown lisT:
<tr><td width="15%" class="options0" id="tdSearchBy" colspan="5">
<input name="r1" value="MeterID" onclick="" type="radio" id="midradio"><font size="4">Meter ID</font></td>
<%
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);
%>
<td width="20%" class="options0" colspan="5">
<select style="WIDTH: 150px" selected="true" name="meterid" id="meter_id" onChange="this.form.submit()" style='display:none;'>
<option>Select Meter ID</option>
<% while(rs.next()) {%>
<option value="<%=rs.getInt("MeterID")%>"><%=rs.getInt("MeterID")%></option>
<% }
rs.close();
st.close();
con.close();
%>
</select>
</td></tr>
The following code is for Subzone dropdown list:
<tr><td class="options1" id="tdSearchBy" colspan="5">
<input name="r1" value="Subzone" onclick="searchOptions(3)" value="subzone" type="radio" checked="checked" id="subzonerd"><font size="4">Sub zone</font></td>
<%
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/suwatermeter","root","sumith");
String getZoneName=request.getParameter("zonelist");
sqlQuery="select distinct Subzone from Meter_List where Zone='"+getZoneName+"'" ;
st=con.createStatement();
rs=st.executeQuery(sqlQuery);
%>
<td width="20%" class="options0" id="tdSearchBy" colspan="5">
<select style="WIDTH: 150px" name="subzonelist" id="subzone_list" onchange="this.form.submit()">
<option value="SZ">Select a Sub Zone</option>
<% while(rs.next()){ %>
<option value="<%=rs.getString("Subzone")%>"><%=rs.getString("Subzone")%></option>
<% }
rs.close();
st.close();
con.close();
%>
</select>
please help me.