Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/02/2010, 02:55
rrecarte
 
Fecha de Ingreso: agosto-2008
Mensajes: 367
Antigüedad: 15 años, 8 meses
Puntos: 5
mostrar un div u otro segun select

buenas... tengo una consulta que nos e como realizar..

seria algo asi., tengo un select (categoria) el cual muestra. auto moto camiones camionetas otros...

presiso que segun el que se elija aqui. se muestre un div u otro.. sson 3 div.. si se elije camion camionetas autos se muestre uno. si se elije moto se muestre otro y si se elije (otro) se muestre otro div, lo supe hacer pero en una forma mas fracil para otra cosa.. asi

<script type="text/javascript">

function showMe (it, box) {
var vis = (box.checked) ? "block" : "none";
var vis2 = (vis == 'block') ? 'none' : 'block';
document.getElementById(it).style.display = vis;
document.getElementById('resultado').style.display = vis2;

// agregale el atributo id al input...

}

</script>

lo cual me marcho.. pero no lo se hacer aqui. ya que no me entiendo mucho con js
tengo esta consulta




<script type="text/javascript">
var peticion = null;

function inicializa_xhr() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}

function muestraProvi() {
if (peticion.readyState == 4) {
if (peticion.status == 200) {
var lista = document.getElementById("provincia");
var provi = eval('(' + peticion.responseText + ')');

lista.options[0] = new Option("selecciona");
var i=1;
for(var codigo in provi) {
lista.options[i] = new Option(provi[codigo], codigo);
i++;
}
}
}
}

function cargaMun() {
var lista = document.getElementById("provincia");
var provincia = lista.options[lista.selectedIndex].value;
if(!isNaN(provincia)) {
peticion = inicializa_xhr();
if (peticion) {
peticion.onreadystatechange = muestraMun;
peticion.open("POST", "http://localhost/uploadveiculos/cargaMuJSON.php?nocache=" + Math.random(), true);
peticion.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
peticion.send("provincia=" + provincia);
}
}
}

function muestraMun() {
if (peticion.readyState == 4) {
if (peticion.status == 200) {
var lista = document.getElementById("municipio");
var municipios = eval('(' + peticion.responseText + ')');

lista.options.length = 0;
var i=0;
for(var codigo in municipios) {
lista.options[i] = new Option(municipios[codigo], codigo);
i++;
}
}
}
}


window.onload = function() {
peticion = inicializa_xhr();
if(peticion) {
peticion.onreadystatechange = muestraProvi;
peticion.open("GET", "http://localhost/uploadveiculos/cargaProJSON.php?nocache="+Math.random(), true);
peticion.send(null);
}

document.getElementById("provincia").onchange = cargaMun;
}
</script>
cuando se realize onchange en la funcion muestraprovi.... segun lo que se haya elegido se tiene que mostrar un div.. muestra provi trae auto moto camineta camiones otro.. espero me puedan ayudar