Hai,
I a have JSP page containing a registration form.The registration form contains a text box and a drop down list box with 1-7 option values. I have entered data into the text box and selected the option value in the drop down list box . After the clicking on submit button and when i login i can retrieve only the text box value and cannnot retrieve the selected option value from drop down list box from the database. How do i get the value which i have selected from the drop down list box from the database.

you may have problems if you did not use attribute "id" in your "select" tag. Attribute "name" is supported too, but this is only optional, "id" is what you should use

PS: If this does not solve issue then please post code

you may have problems if you did not use attribute "id" in your "select" tag. Attribute "name" is supported too, but this is only optional, "id" is what you should use

PS: If this does not solve issue then please post code

I am using attribute id also and it is stored in a string q.

String sql="select * from tablename where id='"+q+"'";
ResultSet rs=st.executeQuery(sql);
if(rs.next())
{
out.print(rs.getString("id"));
}

This is the code i am using

<tr>
        <td width="498" height="25">&nbsp;Required Experience</td>
       <% if (q!= null)
            {
            %>
         <td width="1426" height="97"><SELECT size=1 name="Required Experience">
        <OPTION value=0 selected><%=rs.getString("Required Experience")%></OPTION>
               <option value="Not Specified">Not Specified</option>
               <option value="1 To 2 Years">1 To 2 Years</option>
               <option value="2 To 3 Years">2 To 3 Years</option>
               <option value="3 To 4 Years">3 To 4 Years</option>
               <option value="4 To 5 Years">4 To 5 Years</option>
               <option value="5 To 6 Years">5 To 6 Years</option> 
               <option value="6 To 7 Years">6 To 7 Years</option>
               <option value="7 To 8 Years">7 To 8 Years</option>
               <option value="More than 8 Years">More than 8 Years</option>
        </select></td>
          
               <%   }
        else
        { %>
        <td width="498" height="25">Required Experience</td>
        <td width="1426" height="97"><SELECT size=1 name="Required Experience">
               <option value="Not Specified">Not Specified</option>
               <option value="1 To 2 Years">1 To 2 Years</option>
               <option value="2 To 3 Years">2 To 3 Years</option>
               <option value="3 To 4 Years">3 To 4 Years</option>
               <option value="4 To 5 Years">4 To 5 Years</option>
               <option value="5 To 6 Years">5 To 6 Years</option> 
               <option value="6 To 7 Years">6 To 7 Years</option>
               <option value="7 To 8 Years">7 To 8 Years</option>
               <option value="More than 8 Years">More than 8 Years</option>
        </select>
      <% } %>
      </td>
      </tr>

so, when i execute it i am getting the correct selected value on the top, but all the list of values in the drop down list are displayed again. Can you solve it.

No I cannot, you provided only small portions of the code. I do not see how you retrieving data submitted by form.
As "id" attribute I was referring to attribute in the HTML form not what ever is your return from database.
Lastly you doing direct connection from JSP to DB which is plain wrong.

No I cannot, you provided only small portions of the code. I do not see how you retrieving data submitted by form.
As "id" attribute I was referring to attribute in the HTML form not what ever is your return from database.
Lastly you doing direct connection from JSP to DB which is plain wrong.

As i have mentioned this is a regsitration form and i have to edit the details which i have entered.

This is my complete code in the jsp page.
The Include.jsp contains the database connection string that is.

<%@ page import="java.sql.*"%>
<%@ include file="Include.jsp"%>


<%@ page import = "java.sql.*"%>
<%Class.forName("org.gjt.mm.mysql.Driver");
Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3307/jaz", "root", "root");
%>



<%@ page import="java.sql.*"%>
<%@ include file="Include.jsp"%>
<%
Statement st=con.createStatement();
String q=request.getParameter("id");
String sql="select * from tablename where id='"+q+"'";
ResultSet rs=st.executeQuery(sql);
if(rs.next())
{
out.print(rs.getString("id"));
}
%>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Name</title>
</head>
<script>
function ex1()
{     
      if(document.f1.JobID.value=="")
	   {
		   alert("JobID field is empty");
		   f1.JobID.focus()
		   return false;
	   }

if(document.f1.RequiredEducation.value=="")
	   {
		   alert("RequiredEducation field is empty");
		   f1.RequiredEducation.focus()
		   return false;
	   }
</script>
 <body> 
    <div align="top">
       <table border="0" cellpadding ="0" cellspacing="0" width="1%"><tr>
          <td width="100%" style="float: left">
            <form method="POST" name="f1" action="Editjobs6.jsp" onSubmit="return    ex1()">
              <div align="top" style="width: 354; height:1">
            </div>        
          <table border="0" width="174" cellspacing="0" cellpadding="0" height="911">
      <tr>
<TD width="699" bgColor=#c0c0c0 colSpan=2 height=21>
<P align=center><font color="#000000"><b>Job Details</b></font></P></TD>
      </tr>
        
        <tr>
        <td width="498" height="22">Job ID</td>
        <td width="1426" height="22"><input type="text" value="<%=rs.getString("JobID")%>" name="JobID" size="26"></td>
      </tr>
        <tr>
        <td width="498" height="25">&nbsp;Required Experience</td>
       <% if (q!= null)
            {
            %>
         <td width="1426" height="97"><SELECT size=1 ID="ddlre" name="Required Experience">
        
               <option value=0 selected><%=rs.getString("RequiredExperience")%></options>
               <option value="Not Specified">Not Specified</option>
               <option value="1 To 2 Years">1 To 2 Years</option>
               <option value="2 To 3 Years">2 To 3 Years</option>
               <option value="3 To 4 Years">3 To 4 Years</option>
               <option value="4 To 5 Years">4 To 5 Years</option>
               <option value="5 To 6 Years">5 To 6 Years</option> 
               <option value="6 To 7 Years">6 To 7 Years</option>
               <option value="7 To 8 Years">7 To 8 Years</option>
               <option value="More than 8 Years">More than 8 Years</option>
               </select></td>
          
               <%   }
               else
               { %>
               
             <td width="1426" height="97"><SELECT size=1 name="Required Experience">
               <option value="Not Specified">Not Specified</option>
               <option value="1 To 2 Years">1 To 2 Years</option>
               <option value="2 To 3 Years">2 To 3 Years</option>
               <option value="3 To 4 Years">3 To 4 Years</option>
               <option value="4 To 5 Years">4 To 5 Years</option>
               <option value="5 To 6 Years">5 To 6 Years</option> 
               <option value="6 To 7 Years">6 To 7 Years</option>
               <option value="7 To 8 Years">7 To 8 Years</option>
               <option value="More than 8 Years">More than 8 Years</option>
        </select>
      <% } %>
      </td>
      </tr>

With this rs.getString("Parameter name") i am retreving the values from the database.

This article has been dead for over six months. Start a new discussion instead.