PHP - recoger 3 combox

 
Vista:

recoger 3 combox

Publicado por Maria (30 intervenciones) el 15/09/2011 18:02:34
<script>
//hacer que funcione con diferentes navegadores
function requerir(){
try{
req=new XMLHttpRequest();
}catch(err1){
try{
req=new ActiveXObject("Microsoft.XMLHTTP");
}catch(err2){
try{
req=new ActiveXObject("Msxml2.XMLHTTP");
}catch(err3){
req= false;
}
}
}
return req;
}


var peticion=requerir();

function llamarAjaxGETpro(){
var aleatorio=parseInt(Math.random()*999999999);
valor=document.getElementById("id_pais").value;
var url="combox/estado.php?valor="+valor+"&r="+aleatorio;
peticion.open("GET",url,true);
peticion.onreadystatechange =respuestaAjaxpro;
peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
peticion.send(null);
}

function llamarAjaxGETdis(){
var aleatorio=parseInt(Math.random()*999999999);
valor=document.getElementById("id_estado").value;
pais=document.getElementById("id_pais").value;
var url="combox/municipio.php?valor="+valor+"&pais="+pais+"&r="+al eatorio;
peticion.open("GET",url,true);
peticion.onreadystatechange =respuestaAjaxdis;
peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
peticion.send(null);
}

function respuestaAjaxpro(){

if(peticion.readyState==4){
if(peticion.status==200){
//alert(peticion.responseText);
document.getElementById("pro").innerHTML=peticion. responseText;
}else{
alert("ha ocurrido un error"+peticion.statusText);
}
}
}
function respuestaAjaxdis(){

if(peticion.readyState==4){
if(peticion.status==200){
//alert(peticion.responseText);
document.getElementById("dis").innerHTML=peticion. responseText;
}else{
alert("ha ocurrido un error"+peticion.statusText);
}
}
}
</script>
<form action="" method="post" enctype="application/x-www-form-urlencoded" name="form1" id="form1">
<div id="dep" style="width:150px">
<select name="id_pais" id="id_pais" onchange="llamarAjaxGETpro()" >
<option value="0"><? echo $TEXT['registro-s_pais']; ?></option>
<?php
do{
echo '<option value="'.$row_paises['id_pais'].'">'.htmlentities($row_paises['en']).'</option>';
}while($row_paises=mysql_fetch_array($paises));
echo '</select>';
?>
</div >
<div id="pro" style=" width:150px"/>
<select disabled="disabled" style=" width:220px">
<option value="0"><? echo $TEXT['registro-s_estado']; ?></option>
</select>
</div >
<div id="dis" style="width:150px">
<select name="select3" id="select3" style=" width:220px" disabled="disabled">
<option value="0"><? echo $TEXT['registro-s_municipio']; ?></option>
</select>
</div>
</form>

estados.php
<?
mysql_select_db($database_conexion_pais, $conexion_pais);
$query_estados = sprintf("SELECT * FROM estados$ref WHERE id_pais = '$valor' ORDER BY estado ASC");
$estados = mysql_query($query_estados, $conexion_pais) or die(mysql_error());
$row_estados = mysql_fetch_assoc($estados);
$totalRows_estados = mysql_num_rows($estados);

echo'<select id="id_estado" name="id_estado" onchange=llamarAjaxGETdis()>';
echo'<option value="'.'0">'.$TEXT['registro-estado'].'</option>';
do{
echo'<option value="'.$row_estados['id_estado'].'">'. htmlentities($row_estados['estado']).'</option>';
}while($row_estados=mysql_fetch_array($estados));
echo'</select>';

?>


municipios.php

<?
mysql_select_db($database_conexion_pais, $conexion_pais);
$query_municipios = sprintf("SELECT * FROM municipios_$ref WHERE id_estado = '$valor' ORDER BY municipio ASC");
$municipios = mysql_query($query_municipios, $conexion_pais) or die(mysql_error());
$row_municipios = mysql_fetch_assoc($municipios);
$totalRows_municipios = mysql_num_rows($municipios);
echo'<select id="id_municipio" name="id_municipio" >';
echo'<option value="'.'0">'.$TEXT['registro-municipio'].'</option>';
do{
echo'<option value="'.$row_municipios['id_municipio'].'">'.htmlentities($row_municipios['municipio']).'</option>';
}while($row_municipios=mysql_fetch_array($municipi os));
echo'</select>';
?>
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder