Code to build dropbox with java online help
Â
You can include below code in a CSS file.
Â
.classTableRowColor{
 background-color:#E0E0DC;
}
Â
Â
You can include below code in a JSP file.
Â
<select class="classTableRowColor" name="selectCprType" id="selectCprType" onchange="javascript:submitform();">
 <option class="classFontNormal" value="-1">—Select—</option>           Â
 <option class="classFontNormal"  value="1"> New Facility </option>
 <option class="classFontNormal"  value="2"> Re-New Facility </option>
 <option class="classFontNormal"  value="3"> Addition Facility </option>  Â
</select>Â
Â
classTableRowColor , classFontNormal : Â included in the CSS file.
selectCprType : drop down box identification.
onchange="javascript:submitform();" : when selecting an option from the drop down box we can add a JavaScript to performe.
Â
Â
Instead of hard coding, we can get values from a table like MySQL database table
& then you can fill up those values into a vector.
Then in the JSP page, by using a for loop, you can retrieve those valuesÂ
and display in the drop down box. Here is an example code.
Â
Â
Below is the example method which retrieves data from MySQL Database table
and fill into a vector.Â
  Â
public Vector getCPRTypesAll() throws DasException {
  Â
  String sql;
  ResultSet rs;
  PreparedStatement stmt1;
  Vector vList;
  sql = "";
  rs = null;
  stmt1 = null;
  CPRType cprType = null;
  vList = new Vector();
  try
  {
    con = dbConnect.getConnection();
Â
    sql = "SELECT * FROM cprtype WHERE status=1";
    Â
    stmt1 = con.prepareStatement(sql);
    rs = stmt1.executeQuery();
    try
    {
      while(rs.next())Â
      {
        cprType = new CPRType();
        cprType.setID(rs.getInt("cprtypeid"));
        cprType.setCprType(rs.getString("cprtype"));
        vList.add(cprType);
      }
    }
    catch(Exception e)
    {
      Â
      throw new DasException(errorManupilation.GetErrorMessage(e, "getCPRTypesAll "));
    }
    stmt1.close();
    rs.close();
  }
  catch(Exception e)
  {
    Â
    throw new DasException(errorManupilation.GetErrorMessage(e, "getCPRTypesAll "));
  }
Â
  try
  {
    stmt1.close();
    rs.close();
    con.close();
  }
  catch(SQLException ex)
  {
    Â
    throw new DasException(errorManupilation.GetErrorMessage(ex, "getCPRTypesAll "));
  }
  Â
  try
  {
    stmt1.close();
    rs.close();
    con.close();
  }
  catch(SQLException ex)
  {
    Â
    throw new DasException(errorManupilation.GetErrorMessage(ex, "getCPRTypesAll "));
  }
  cprType = null;
  return vList;
}
Â
Â
Below code can be included in a JSP page.
<%
Vector vCprTypes = new Vector();
CPRMasterTxn cprmt = new CPRMasterTxn();
Â
try{
 //Retrieving vector by calling the method.
 vCprTypes = cprmt.getCPRTypesAll();
}catch(Exception e){System.out.println(e.getMessage());}
%>
Â
Â
Â
Applying to a drop down list for dynamic change.
Â
<select class="classTableRowColor8" name="selectCprType<%=cprmd.getID()%>" id="redirecturl<%=cprmd.getID()%>" onchange="javascript:submitform('<%=cprmd.getID()%>');">
 <option value="-1">—Select—</option>           Â
 <% try{
 if(vCprTypes != null){
 cprType = new CPRType();
 for (int k=0; k< vCprTypes.size() ; k++){      Â
  cprType = (CPRType)vCprTypes.elementAt(k);  Â
 %>
  <option class="classFontNormal"  value="<%=cprType.getID()%>"><%=cprType.getCprType()%></option>
 <%}}
 }catch(Exception e){System.out.println("Looping error = "+e.getLocalizedMessage());}
 %>  Â
</select>Â
Â