Ir para conteúdo

POWERED BY:

Arquivado

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

regina

Exibir e ocultar

Recommended Posts

Olá a todos!eu tenho o seguinte código para exibir e ocultar divs:

var visibleVar="null";	if (navigator.appName == "Netscape") {				layerStyleRef="layer.";				layerRef="document.layers";				styleSwitch="";				visibleVar="show";	} else {				layerStyleRef="layer.style.";				layerRef="document.all";				styleSwitch=".style";				visibleVar="visible";	}	function showLayer(layerName){		eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+visibleVar+'"');	}	function hideLayer(layerName){		eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');	}
e uso assim num form:
Tipo da Empresa <strong title="Requirido" class="requirido">*</strong> <br/> 		<input name="emp_tipo" type="radio" value="juridica" onclick="java script:hideLayer('cpf');showLayer('cnpj');" class="radio_oculto" <?php if (($tipo=="juridica") OR ($tipo=="")) echo "checked=\"checked\""; ?> />Pessoa Jurídica                                                                          		<input name="emp_tipo" type="radio" value="fisica" onclick="java script:hideLayer('cnpj');showLayer('cpf');" class="radio_oculto" <?php if ($tipo=="fisica") echo "checked=\"checked\""; ?>/> Pessoa Física	<div id="cnpj" <?php if (($tipo=="juridica") OR ($tipo=="")) echo "style=\"width:35%; float:left;\""; else echo "style=\"width:35%; float:left; visibility: hidden;\""; ?>>	  C.N.P.J.: <input type="text" name="emp_cnpj" id="emp_cnpj" class="input_oculto" maxlength="18" size="18" tabindex="1" title="CNPJ" onKeyPress="return txtBoxFormat(this.form, this.name, '99.999.999/9999-99', event);" onchange="window.location = 'empresa_pesquisar_cnpj.php?emp_cnpj=' + document.getElementById('emp_cnpj').value; return false;" <?php if ($tipo=="juridica") echo "value=".$cod; ?> />	</div>	<div id="cpf" <?php if ($tipo=="fisica") echo "style=\"width:55%; float:right;\""; else echo "style=\"width:50%; float:right; visibility: hidden;\""; ?>>	  <div style="float:left">	  C.P.F.:<input type="text" name="emp_cpf" id="emp_cpf" class="input_oculto" maxlength="14" size="20" tabindex="1" title="C.P.F." onkeypress="return txtBoxFormat(this.form, this.name, '999.999.999-99', event);" onBlur="window.location = 'empresa_pesquisar_cpf.php?emp_cnpj=' + document.getElementById('emp_cpf').value; return false;" <?php if ($tipo=="fisica") echo "value=".$cod; ?> /> </div>	</div>
Funciona QUASE corretamente no IE (não formata a máscara) porém não funciona nada no Firefox.Erros listados pelo IE:

'undefined' é nulo ou não é um objeto

Erros listados pelo Firefox:

document.layers has no properties

clicando exibe destaque sobre a seguinte linha:
eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
Onde estou errando?Agradeço desde já a quem puder me ajudar :)

Compartilhar este post


Link para o post
Compartilhar em outros sites

ESqueça este esquema de document.layers ou document.all, o certo é usar document.getElementById.

 

Como você não tem IDs no seu HTML, fiz um esquema aqui com o getElementsByName.

 

Troque as duas funções por isto:

function showLayer(layerName){document.getElementsByName(layerName)[0].style.visibility = "visible";	}	function hideLayer(layerName){document.getElementsByName(layerName)[0].style.visibility = "hidden";	}
Nem cheguei a testar, mas a idéia e esta.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ahnnn sim, é que seu html está com ID (o certo) e não com name como eu achei que estava.

 

Faz assim:

function showLayer(layerName){document.getElementById(layerName).style.visibility = "visible";	}	function hideLayer(layerName){document..getElementById(layerName).style.visibility = "hidden";	}

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.