Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Display adjacent Combo Box against Event

$
0
0
I have this Servlet source code. Here I have one ComboBox(which will be displayed initially). When user selects one of its item one new ComboBox shall popup next(adjacent) to it, but my code is not able to do this. I don't know what I am failing in...?

import java.util.*;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class God4 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    	response.setContentType("text/html");
    	PrintWriter out = response.getWriter();
		out.println("<html>") ;
			out.println("<head>");
				out.println("<script>") ;
					out.println("function formSubmit()") ;
						out.println("{") ;
							out.println("document.forms[\"myForm\"].submit() ;") ;
							Enumeration e = request.getParameterNames();
							while (e.hasMoreElements()) 
								{
									String pName = (String) e.nextElement();
									String[] pValues = request.getParameterValues(pName);
									for (int i=0;i<pValues.length;i++) 
										{
											try
												{
													ArrayList<String> a = new returnCities().returning((String)pValues[i]) ;
													for(int j=0;j<a.size();j++)
														{
															out.println("var selector=document.createElement(\"select\");") ;
															out.println("var cel=document.getElementById(\"Cell\");") ;
															out.println("cel.appendChild(selector);") ;
															out.println("var option = document.createElement(\"option\");") ;
															out.println("option.value=\""+(String)a.get(j)+"\";") ;
															out.println("option.appendChild(document.createTextNode(\""+(String)a.get(j)+"\"));");
															out.println("selector.appendChild(option);") ;
														}
												}
											catch(SQLException f) {}
										}
								}
						out.println("}") ;
				out.println("</script>") ;
			out.println("</head>") ;
	
			out.println("</body>") ;
				out.println("<form name=\"myForm\"  method=\"get\">") ;
					out.println("<div id=\"cell\">") ;
					out.println("<select name=\"selectbox\" onchange=\"formSubmit()\" value=\"Send from Data!\">") ;
						out.println("<option value=\"Uttar Pradesh\">Uttar Pradesh</option>") ;
						out.println("<option value=\"Rajasthan\">Rajasthan</option>") ;
						out.println("<option value=\"Mumbai\" selected=\"selected\">Mumbai</option>") ;
						out.println("<option value=\"Bihar\">Bihar</option>") ;
					out.println("</select>") ;
					out.println("</div>") ;
				out.println("</form>") ;
			out.println("</body>") ;
		out.println("</html>") ;
  	}
  	public void doPost(HttpServletRequest request, HttpServletResponse 	response) throws IOException, ServletException {
    	doGet(request, response);
  	}
}



import java.sql.*;
import java.util.*;

class returnCities
	{
		ArrayList<String> al,a2,a3 ;
		
		public ArrayList<String> returning(String state)throws SQLException
			{
				ArrayList<String> al = getCities(state) ;
				return al ;
			}
				
		public ArrayList<String> getCities(String st)throws SQLException
			{
				ArrayList<String> al = new ArrayList<String>() ;
				
				try 
                    {
                        Class.forName("com.mysql.jdbc.Driver").newInstance() ; 
                    }
                catch(Exception e)
                    { 
                        System.out.println(e);
                    }
                
                String url = "jdbc:mysql://localhost:3306/student";
                String username = "root" ;
				String password = "twinrdmighty" ;
				Connection con = DriverManager.getConnection(url, username, password) ;
				Statement stat = con.createStatement() ;
				
				ResultSet rs = stat.executeQuery("select city from sc where state='"+st+"'") ;
				
				while(rs.next())
					{
						al.add(rs.getString("city")) ;
					}
				return al ;
			}
	}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>