Ir para conteúdo

POWERED BY:

Arquivado

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

Danilo Pessoa

Consistir 3 valore em JavaScript

Recommended Posts

Galera...

To com o seguinte problema!

 

Tenho um Form com um <select> de Paises.

 

Quando o usuário Seleciona Brasil o formulário apresenta o campo de Endereço pro Brasil, quando seleciona qualquer outro pais ele mostra o campo de endereço Internacional, mas quando ele seleciona a opção "Selecione um item" que é vazio ele mantem a mostra o campo de endereço do Brasil ou do Internacional que foi o ultimo selecionado.

 

O meu javascript ta assim e funciona apenas para os 2 casos reais, mas para o valor vazio não... Como faço essa consistência de 3 valores?

 

function mostra(valor) {
var internacional = document.getElementById('Internacional');
var nacional = document.getElementById('Nacional');

if (valor == "1") {
	internacional.style.display = 'none';
	nacional.style.display = '';
}else  {
	nacional.style.display = 'none';
	internacional.style.display = '';
}
}

 

 

E meu Form ta assim:

 

<tr valign="baseline">
			<td height="25" colspan="2" bgcolor="#FFFFFF"><br /> PAÍS / <em
			style="font-weight: 100;">Country</em> <br /> <input type="hidden" name="paisid" id="paisid"
			value="<?php echo $this->paisid->id;?>"><select
			name="pais_id" id="pais_id" onChange="mostra(this.value);">
			<option value="">Selecione / Select</option>
			<?php foreach ($this->pais as $p) {?>
			<option value=<?php echo $p->id;?>>
			<?php echo $p->titulo;?>
			</option>
			<?php }?>
			</select> <br /> <br />
			</td>
</tr>

 

<div id="Nacional" style="display: none">
					<table width="90%" border="0" align="left" cellpadding="0"
						cellspacing="0">
						<tr>
							<td height="27" colspan="3" bgcolor="#EEEEEE"
								style="font-size: 14px;">  Endereço</td>
						</tr>
						<tr>
							<td valign="baseline"><br /> Tipo <br /> <label><select
									name="tipoLogradouro" id="tipoLogradouro"
									onchange="mostra(this.value)">
										<option value="Selecione">Selecione</option>
										<?php foreach ($this->tpLogradouro as $tp) {?>
										<option value=<?php echo $tp->id;?>
											" <?php if ($tp->id == $this->end->tipoLogradouro_id) :?>
											selected <?php endif?>>
											<?php echo $tp->titulo; ?>
										</option>
										<?php }?>

								</select> </label>
							</td>
							<td colspan="2"><label> <br /> Logradouro e número<br /> <input
									name="logradouro" type="text" style="color: gray;"
									id="logradouro" value="<?php echo $this->end->logradouro;?>"
									size="20" /><input type="hidden" name="endereco_id"
									id="endereco_id" value="<?php echo $this->end->id ?>" /> </label>
							</td>
							<!-- ><td><label> <br /> Número <br /> <input
								name="numero_end" type="text" style="color: gray;"
								id="numero_end" value="" size="5" maxlength="5" /> </label></td>-->
						</tr>
						<tr>
							<td width="80">CEP <br /> <label> <input name="cep" type="text"
									id="cep" style="color: gray;"
									value="<?php echo $this->end->cep;?>" size="12" maxlength="9" />
							</label>
							</td>
							<td width="80">Estado <br /> <label> <select name="estado_id"
									id="estado_id">
										<option value="Selecione">Selecione</option>
										<?php foreach ($this->estado as $est) {?>
										<option value=<?php echo $est->id;?>
											" <?php if ($est->id == $this->end->estado_id) : ?> selected
											<?php endif?>>
											<?php echo $est->titulo;?>
										</option>
										<?php }?>
								</select> </label>
							</td>
							<td width="160">Cidade <br />
								<div id="dvmunicipio">
									<select name="municipio_id" id="municipio_id">
										<option value="Selecione">Selecione</option>
										<?php foreach ($this->municipio as $mun) {?>
										<option value=<?php echo $mun->id;?>
										<?php if ($mun->id == $this->end->municipio_id) : ?>
											selected <?php endif?>>
											<?php echo $mun->titulo;?>
										</option>
										<?php }?>
									</select>
								</div>
							</td>
						</tr>
						<tr>
							<td colspan="3"> </td>
						</tr>
					</table>
				</div>

 

 

Obrigado a todos que puderem contribuir a favor da disseminação do conhecimento.

 

Abraço!

Compartilhar este post


Link para o post
Compartilhar em outros sites

estude sobre else if()

 

       if (valor==1 )
           // nacional
       else if( valor==2 )
           //internacional
       else
           //nenhum dos outros 2

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.