Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Bruno Depieri Barduchi

Selecionar id do option de um select

Recommended Posts

Galera, seguinte

 

Tenho um formulário com vários selects, porém 1 em específico (estado civil) existe uma opção para abrir uma div e o cliente preencher com os dados, porém eu preciso comparar o id do option se ele tem a opção para abrir essa div ou não (opção casado id=1), porque se for outra opção (id=2) não abre.

As informações vêm do banco

 

Como faço isso?

 

Lembrando que não sou programador de Java Script.

 

Tentei esse fonte:

 

<script type="text/javascript">
window.onload = function(){
    id('id_estadocivil_cliente').onchange = function(){
        if( this.value==1){
            id('conjugue').style.display = 'block';
		}else{
            id('conjugue').style.display = 'none';
		}
    }
}
function id( el ){
    return document.getElementById( el );
}
</script>
<form>
     <fieldset>

            <!-- id_estadocivil_cliente -->				
            <label for="id_estadocivil_cliente">Estado Civil:</label>
            <select name="id_estadocivil_cliente" id="id_estadocivil_cliente"
            	            >
                <option value=""  selected="selected"><< SELECIONE >></option>
            	<option value="1" id="1">Casado(a)</option><option value="2" id="2">Divorciado(a)</option><option value="3" id="2">Solteiro(a)</option><option value="4" id="2">Desquitado(a)</option>            </select>
            <br />
            <br />
            <div  id="conjugue" style="display:none">
                <!-- nome -->
                <label for="nome_conjugue_cliente" title="nome_conjugue_cliente" >Nome:</label>
                <input id="nome_conjugue_cliente" name="nome_conjugue_cliente" alt="nome_conjugue_cliente" title="nome_conjugue_cliente" type="text"  />
                <br />
                <!-- sobrenome -->
                <label for="sobrenome_conjugue_cliente" title="sobrenome_conjugue_cliente" >Sobrenome:</label>
                <input id="sobrenome_conjugue_cliente" name="sobrenome_conjugue_cliente" alt="sobrenome_conjugue_cliente" title="sobrenome_conjugue_cliente" type="text"  />
                <br />
                <!-- genero_conjugue_cliente -->				
                <label for="genero_conjugue_cliente">Gênero:</label>
                <select name="genero_conjugue_cliente" id="genero_conjugue_cliente"
            	            >
                    <option value=""  selected="selected"><< SELECIONE >></option>
					<option value="1">Feminino</option><option value="2">Masculino</option>                </select>
                <br />
                <!-- nascimento -->
                <label for="datanascimento_conjugue_cliente" title="datanascimento_conjugue_cliente" >Data de Nascimento:</label>
                <input id="datanascimento_conjugue_cliente" name="datanascimento_conjugue_cliente" alt="datanascimento_conjugue_cliente" title="datanascimento_conjugue_cliente" type="text"  />
                <br />
                <!-- email -->
                <label for="email_conjugue_cliente" id="email_conjugue_cliente" title="email_conjugue_cliente" >Email:</label>
                <input id="email_conjugue_cliente" name="email_conjugue_cliente" alt="email_conjugue_cliente" title="email_conjugue_cliente" type="text"  />
                <br />
                <!-- telefone -->
                <label for="telefone_conjugue_cliente" title="telefone_conjugue_cliente" >Telefone:</label>
                <input id="telefone_conjugue_cliente" name="telefone_conjugue_cliente" alt="telefone_conjugue_cliente" title="telefone_conjugue_cliente" type="text"  />
                <br />
                <!-- celular -->
                <label for="celular_conjugue_cliente" title="celular_conjugue_cliente" >Celular:</label>
                <input id="celular_conjugue_cliente" name="celular_conjugue_cliente" alt="celular_conjugue_cliente" title="celular_conjugue_cliente" type="text"  />
                <br />
                <br />
            </div>
            <input type="submit" name="" id="enviar10" class="botao" value="Enviar" />
            <input type="hidden" name="id_action_cliente" value="1" />	
        </fieldset>
    </form>

 

no Java script tem o comparadr this.value, ele compara o valor e eu preciso do id, achei um fonte interessante mas não consegui aplicar.(http://stackoverflow.com/questions/1904827/how-to-get-selected-option-id)

 

 

fico no aguardo

 

Vlw e t+

Compartilhar este post


Link para o post
Compartilhar em outros sites

eis aí a solução:

 

<script type="text/javascript">
window.onload = function(){
    var select_ = id('id_estadocivil_cliente');
    select_.onchange = function(){
        if(this.options[select_.selectedIndex].id==1){
            id('conjugue').style.display = 'block';
        }else{
            id('conjugue').style.display = 'none';
        }
    }
}
function id( el ){
    return document.getElementById( el );
}
</script>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.