Bueno solo posteo el código importante o el que realiza las acciones que pido, si necesitan los otros archivos los subiré.
El código es el siguiente:
Código:
<?php
if($_POST) {
print_r($_POST);
}
if(isset($_POST['submit'])) {
$provincia = "'".$_POST['provincia']."',";
$municipio .= "'".$_POST['municipio']."'";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ejercicio 16 - Listas desplegables encadenadas</title>
<script type="text/javascript" src="util.js"></script>
<script type="text/javascript">
function muestraProvincias() {
var lista = document.getElementById("provincia");
var documento_xml = this.req.responseXML;
var provincias = documento_xml.getElementsByTagName("provincias")[0];
var lasProvincias = provincias.getElementsByTagName("provincia");
lista.options[0] = new Option("- selecciona -");
// Método 1: Crear elementos Option() y añadirlos a la lista
for(i=0; i<lasProvincias.length; i++) {
var codigo = lasProvincias[i].getElementsByTagName("codigo")[0].firstChild.nodeValue;
var nombre = lasProvincias[i].getElementsByTagName("nombre")[0].firstChild.nodeValue;
lista.options[i+1] = new Option(nombre, codigo);
}
// Método 2: crear el código HTML de <option value="">...</option> y utilizar el innerHTML de la lista
/*
var codigo_html = "";
codigo_html += "<option>- selecciona -<\/option>";
for(var i=0; i<lasProvincias.length; i++) {
var codigo = lasProvincias[i].getElementsByTagName("codigo")[0].firstChild.nodeValue;
var nombre = lasProvincias[i].getElementsByTagName("nombre")[0].firstChild.nodeValue;
codigo_html += "<option value=\""+codigo+"\">"+nombre+"<\/option>";
}
// La separacion siguiente se tiene que hacer por este bug de microsoft:
// http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
var esIE = navigator.userAgent.toLowerCase().indexOf('msie')!=-1;
if(esIE) {
document.getElementById("provincia").outerHTML = "<select id=\"provincia\">"+codigo_html+"</select>";
}
else {
document.getElementById("provincia").innerHTML = codigo_html;
}
*/
}
function cargaMunicipios() {
var lista = document.getElementById("provincia");
var provincia = lista.options[lista.selectedIndex].value;
if(!isNaN(provincia)) {
var cargador = new net.CargadorContenidosCompleto("http://localhost/bajotecho/cargaMunicipiosXML.php?nocache="+Math.random(),
muestraMunicipios,
muestraError,
"POST",
"provincia="+provincia,
"application/x-www-form-urlencoded");
}
}
function muestraError() {
alert("[ERROR] No se han podido cargar los municipios por un problema técnico.");
}
function muestraMunicipios() {
var lista = document.getElementById("municipio");
var documento_xml = this.req.responseXML;
var municipios = documento_xml.getElementsByTagName("municipios")[0];
var losMunicipioss = municipios.getElementsByTagName("municipio");
// Borrar elementos anteriores
lista.options.length = 0;
// Se utiliza el método de crear elementos Option() y añadirlos a la lista
for(i=0; i<losMunicipioss.length; i++) {
var codigo = losMunicipioss[i].getElementsByTagName("codigo")[0].firstChild.nodeValue;
var nombre = losMunicipioss[i].getElementsByTagName("nombre")[0].firstChild.nodeValue;
lista.options[i] = new Option(nombre, codigo);
}
}
window.onload = function() {
var cargador = new net.CargadorContenidos("http://localhost/bajotecho/cargaProvinciasXML.php?nocache="+Math.random(), muestraProvincias);
document.getElementById("provincia").onchange = cargaMunicipios;
}
</script>
</head>
<body>
<h1>Listas desplegables encadenadas</h1>
<form name="form1" method="post" action="">
<label for="provincia">Provincia</label>
<select id="provincia">
<option>Cargando...</option>
</select>
<br/><br/>
<label for="municipio">Municipio</label>
<select id="municipio">
<option>- selecciona una provincia -</option>
</select>
<label for="Submit"></label>
<input type="submit" name="submit" value="Enviar" id="submit" />
</form>
</body>
</html>
Gracias de antemano.

