javascript - how to remove duplicate values from my select dropdown list? -
this jsp code:
<form method="post" action="" > <table style="width: 100%;border: 0px;border-spacing: 0px;padding: 0px;"> <tr> <td style="height: 28px; font-size: 14px; width:80px; ">select state :</td> <td style="text-align: left; padding-left: 10px; width: 450px;"> <select name="city" onchange="consituteshow(this.value)"> <option value="">andhra pradesh</option> <% statement stmt=null; dbconnection db=new dbconnection(); connection con=db.dbconn(); try{ stmt = con.createstatement(); resultset rs = stmt.executequery("select distinct stateid,state election_history;"); while(rs.next()) { %> <option value="<%=rs.getstring(2)%>"><%=rs.getstring(2)%></option> <%}%> </select> </td> </tr> </table> </form>
above jsp code , in code have given 'andhra pradesh' default name.due inside dropdown list 'andhra pradesh' printed twice.is there way remove it???
check if name "andhra pradesh" , if select option selected="selected"
<!-- no default option here --> <option value=""></option> <% while(rs.next()){ if( !rs.getstring(2).equals("andhra pradesh") ){ <option value="<%=rs.getstring(2)%>"><%=rs.getstring(2)%></option> }else{ <option selected="selected" value="<%=rs.getstring(2)%>"><%=rs.getstring(2)%></option> } } %>
Comments
Post a Comment