Ver Mensaje Individual
  #4 (permalink)  
Antiguo 30/03/2010, 16:06
Avatar de salbatore
salbatore
 
Fecha de Ingreso: abril-2007
Ubicación: Springfield
Mensajes: 1.567
Antigüedad: 17 años, 1 mes
Puntos: 19
Respuesta: Bloquear campos en un formulario

Hola konoyek,

No se como tienes el formulario... mira el codigo que acabo de hacerte. Es sencillo y tosco... pero funciona perfectamente. Lo que hace es ocultar los campos que no son necesarios dependiendo del genero, ademas de ocultarlos los deshabilita:

Código PHP:
<script>
    function 
eleccion_de_sexo(opcion)
        {
            if(
opcion!='')
                {
                    if(
opcion=='hombre')
                        {
                            
                            
document.getElementById('hombre').style.display='block';
                            
document.getElementById('mujer').style.display='none';
                            
                            
document.getElementById('hombre_select').disabled false;
                            
document.getElementById('mujer_select').disabled true;
                        }
                    if(
opcion=='mujer')
                        {
                            
document.getElementById('hombre').style.display='none';
                            
document.getElementById('mujer').style.display='block';
            
                            
document.getElementById('hombre_select').disabled true;
                            
document.getElementById('mujer_select').disabled false;
                        }
                }
            else
                {
                    
document.getElementById('hombre').style.display='none';
                    
document.getElementById('mujer').style.display='none';
    
                    
document.getElementById('hombre_select').disabled true;
                    
document.getElementById('mujer_select').disabled true;
                }
        }
</script>
    <fieldset id="sexo">
        <legend>Eleccion del sexo</legend>
        <select onChange="eleccion_de_sexo(this.value)" autocomplete="off" style="width:100%;">
            <option selected="selected" value="">Selcciona tu sexo</option>
            <option value="hombre">Hombre</option>
            <option value="mujer">Mujer</option>
        </select>
    </fieldset>
    
    <fieldset id="hombre" style="display:none; background:brown">
        <legend>Datos especificos de la hombre</legend>
        <select id="hombre_select" autocomplete="off" style="width:100%;" disabled="disabled">
            <option selected="selected">¿Que deporte te gusta?</option>
            <option value="1">Futbol</option>
            <option value="2">Golf</option>
        </select>
    </fieldset>
    <fieldset id="mujer" style="display:none; background:pink">
        <legend>Datos especificos de la mujer</legend>
        <select id="mujer_select" autocomplete="off" style="width:100%;" disabled="disabled">
            <option selected="selected">¿Que revista te gusta?</option>
            <option value="1">Hola!</option>
            <option value="2">Que me dices!</option>
        </select>
    </fieldset> 
Espero que te sirva!
Te sirve?