Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/06/2011, 16:02
luisfonse
 
Fecha de Ingreso: junio-2011
Mensajes: 1
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: Como llenar un ComboBox

bueno yo lo hice de la siguiente manera para jsp y bd cualquier duda mi correo [email protected] o [email protected] :D , toco ser un poco recursivo =)

<html>
<head>


<title>Estudiantes</title>


<%
Connection conexion=null;
String mensaje="";
/*parametros para la conexion*/
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/bd_notas";//jdbc:mysql://127.0.0.1:3306/invent
String usuario = "root";
String clave = "1234";
String codaux="";

/*procedimiento de la conexion*/
try{
Class.forName(driver);
conexion = DriverManager.getConnection(url,usuario,clave);
} catch (Exception ex){
mensaje=ex.toString();
}

String qry1 = "select * from departamentos ";
Statement stmt1 = conexion.createStatement();
ResultSet rs1 = stmt1.executeQuery(qry1);


%>


</head>
<body>
<div id="art-page-background-simple-gradient">
</div>
<div id="art-page-background-glare">
<div id="art-page-background-glare-image">
<p>&nbsp;</p>

<script language="JavaScript" type="text/javascript">

function llenar(obj)
{
var i=0;
<%

rs1.beforeFirst();
while (rs1.next())
{
String cod1= rs1.getString("departamento");
codaux=cod1;

%>
cod1="<%=codaux%>";

num= parseInt(cod1);
num2=parseInt(obj.value)

if(num==num2)
{
<%
String qry2 = "select * from ciudades where departamento ='"+cod1+"'" ;
Statement stmt2 = conexion.createStatement();
ResultSet rs2 = stmt2.executeQuery(qry2);
while (rs2.next() )
{
String lmf = rs2.getString("noml");
%>
ciudad = "<%=lmf%>"
document.forms.formu.combod[i]= new Option(ciudad)
i++;
<%
}
%>
}
<%
}
%>


}

</script>
<br/>Departamentos:
<form name="formu">
<select onchange="llenar(this)" name="comboc" >
<%
rs1.beforeFirst();
while(rs1.next())
{
String cod1= rs1.getString("departamento");

%>

<option name="<% out.println(cod1); %>" id="<% out.println(cod1); %>" label="<% out.println(cod1); %>" onchange="llenar(this)" value="<% out.println(cod1); %>"><% out.println(cod1); %>
</option>
<%
}
%>
</select>
ciudades:
<select name="combod" style="width:150;">
</select>
</form>
</body>
</html>