Selects con PHP y Base de Datos
Hola.
tengo un problema.
En una p谩gina HTMl tengo un formulario (lista) con dos selects, y el contenido del segundo select depende de lo seleccionado en el primer select.
Por ejemplo, si en el primer select, que se llama pais elijo espa帽a, en el segundo select, llamado provincias, me tienen que salir las provincias de espa帽a.
Por otro lado, en una tabla de mi base de datos, tengo dos campos:pais,provincia.
He logrado que el select pais se me llene con los paises de la base de datos, pero no s茅 c贸mo hacer para que segun elija el pais en ese select, la query a la base de datos tenga como condicion que he elegido ese pais...
驴C贸mo podr铆a hacerlo?
tengo un problema.
En una p谩gina HTMl tengo un formulario (lista) con dos selects, y el contenido del segundo select depende de lo seleccionado en el primer select.
Por ejemplo, si en el primer select, que se llama pais elijo espa帽a, en el segundo select, llamado provincias, me tienen que salir las provincias de espa帽a.
Por otro lado, en una tabla de mi base de datos, tengo dos campos:pais,provincia.
He logrado que el select pais se me llene con los paises de la base de datos, pero no s茅 c贸mo hacer para que segun elija el pais en ese select, la query a la base de datos tenga como condicion que he elegido ese pais...
驴C贸mo podr铆a hacerlo?
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
<!-- aki le vas creando opciones...dandole un numero (ojo con no repetirlo) y luego el valor d opcion dl 1r menu....1, 2, 3 etc -->
arrItems1[0] = "Deixar tarifa";
arrItemsGrp1[0] = 1;
arrItems1[1] = "Venta";
arrItemsGrp1[1] = 1;
arrItems1[2] = "Informaci贸";
arrItemsGrp1[2] = 1;
arrItems1[3] = "Alta client";
arrItemsGrp1[3] = 1;
arrItems1[4] = "Cobrar";
arrItemsGrp1[4] = 2;
arrItems1[5] = "Pagar indemnitzaci贸";
arrItemsGrp1[5] = 2;
arrItems1[6] = "Peritaci贸";
arrItemsGrp1[6] = 2;
arrItems1[7] = "Descens producci贸";
arrItemsGrp1[7] = 2;
arrItems1[8] = "Visita solic. client";
arrItemsGrp1[8] = 2;
arrItems1[9] = "Renovaci贸 tarifes";
arrItemsGrp1[9] = 2;
<!-- -------------------------------------------- -->
function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice")
{
// Empty the third drop down box of any choices
//for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle = document.createElement("option") ;
myEle.value = 0 ;
myEle.text = "[Selecciona]" ;
controlToPopulate.add(myEle) ;
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ )
{
if ( GroupArray[x] == control.value )
{
myEle = document.createElement("option") ;
myEle.value = x ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}
}
}
// End -->
</script>
</HEAD>
<body bgcolor="#3A6EA5">
<!-- aki creas tu formulario...con el primer select con las opciones que kieras y el segundo saldra dependiente.... es decir, como viste arriba...le vas creando los valores del segundo select...y le dices si son d la opcion 0 dl 1r menu , de la opcion 1....etc -->
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
<!-- aki le vas creando opciones...dandole un numero (ojo con no repetirlo) y luego el valor d opcion dl 1r menu....1, 2, 3 etc -->
arrItems1[0] = "Deixar tarifa";
arrItemsGrp1[0] = 1;
arrItems1[1] = "Venta";
arrItemsGrp1[1] = 1;
arrItems1[2] = "Informaci贸";
arrItemsGrp1[2] = 1;
arrItems1[3] = "Alta client";
arrItemsGrp1[3] = 1;
arrItems1[4] = "Cobrar";
arrItemsGrp1[4] = 2;
arrItems1[5] = "Pagar indemnitzaci贸";
arrItemsGrp1[5] = 2;
arrItems1[6] = "Peritaci贸";
arrItemsGrp1[6] = 2;
arrItems1[7] = "Descens producci贸";
arrItemsGrp1[7] = 2;
arrItems1[8] = "Visita solic. client";
arrItemsGrp1[8] = 2;
arrItems1[9] = "Renovaci贸 tarifes";
arrItemsGrp1[9] = 2;
<!-- -------------------------------------------- -->
function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice")
{
// Empty the third drop down box of any choices
//for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle = document.createElement("option") ;
myEle.value = 0 ;
myEle.text = "[Selecciona]" ;
controlToPopulate.add(myEle) ;
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ )
{
if ( GroupArray[x] == control.value )
{
myEle = document.createElement("option") ;
myEle.value = x ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}
}
}
// End -->
</script>
</HEAD>
<body bgcolor="#3A6EA5">
<!-- aki creas tu formulario...con el primer select con las opciones que kieras y el segundo saldra dependiente.... es decir, como viste arriba...le vas creando los valores del segundo select...y le dices si son d la opcion 0 dl 1r menu , de la opcion 1....etc -->
