java - Submitting form with multiple dropdown boxes? -
in below code having multple dropdown boxes inside single form.in dropdown boxes showing default values. when user gets sign in user can change values inside dropdowns , clicks submit button.
<form method="post" id="myform" name="myform"> <% while(rs1.next()) { %> <table id="main_table" style="width: 600px; border: 0px solid #ccc; padding: 1px; border-spacing: 1px; "> <tbody> <tr class="ab" style="background-color:#3f92aa; color:white; width:600px; "> <td colspan="2" class="flip" style="width:125px; font-size:14px; text-align:left; font-family:palatino linotype;"><%=rs1.getstring(3) %><input type="hidden" name="statename" value="goa"></td> <td colspan="2" class="flip" style="width:125px; font-size:14px; text-align:center; font-family:palatino linotype;"><%=rs1.getstring(4) %></td> <td colspan="2" class="flip" style="background-color:#cb3315; width:125px; font-size:14px; text-align:center; font-family:palatino linotype;"><%=rs1.getstring(5) %></td> <td colspan="2" style="width:125px; font-size:13px; font-family:palatino linotype; text-align:center;"> <table style="border: 0px;border-spacing: 0px;padding: 0px;"> <tr> <td> </td> <td> <select name="<%=rs1.getstring(3) %>"> <option value="<%=rs1.getstring(5) %>"><%=rs1.getstring(5) %></option> <% statement stmt2=null; dbconnection db2=new dbconnection(); connection con2=db2.dbconn(); try{ stmt2 = con2.createstatement(); resultset rs2 = (resultset) stmt2.executequery("select distinct winnerparty election_history;"); while(rs2.next()) { %> <option value="<%=rs2.getstring(1) %>"><%=rs2.getstring(1) %></option> <% } } catch(sqlexception e){ e.printstacktrace(); } finally{ con2.close(); stmt2.close(); } %> </select> </td> </tr> </table> </td> </tr> </tbody> </tbody> </table> </form>
servlet code:
con=dbconnection.dbconn(); stmt=con.createstatement(); string statenames=request.getparameter("statename"); system.out.println("this state name ==="+statenames); resultset rs = (resultset) stmt.executequery("select distinct constituency election_history state='"+statenames+"'"); //rs.next(); while(rs.next()){ constituencies.add(rs.getstring(1)); } system.out.println("list of constituencies are=="+constituencies); for(int i=0;i<constituencies.size();i++) { string cname=constituencies.get(i); system.out.println("cname value is=="+cname); string cselected=request.getparameter(cname); system.out.println("cselected value is=="+cselected); map.put(cname, cselected); }
output:
inside editypname... connected database state name ===goa list of constituencies are==[panaji, mormugao] cname value is==panaji cselected value is==null cname value is==mormugao cselected value is==inc
but here whats problem when submiting form getting 1 value(cselected) of dropdown inside servlet can see inside output , remaining values null. can tell me issue here??
if have multiple drop downs named statename
, don't use string statenames = request.getparameter("statename");
rather use:
string[] statenames = request.getparametervalues("statename");
Comments
Post a Comment