Função Javascript ocultar/exibir um DIV

Bom dia senhores(as),
Eu preciso fazer uma função básica em JS para ocultar/exibir um DIV (gridEmail)
Eu fiz buscando pelo document.getElementById, mas dá erro…fala que o objeto não existe.

<html:form action="/undertaker/funcionario.do?method=doConfirm" focus="nome" styleId="searchform">
    <input name="action" id="action" type="hidden" value="<%=action%>" >
    <input name="idFuncionario" id="idFuncionario" type="hidden" value='<bean:write name="dto" property="idFuncionario"/>'>

[b]
    <div id="gridEmail" style="display:none">
        <input type="text" name="email" id="email" class="textbox" value='<bean:write name="dto" property="email"/>'>
    </div>
[/b]

    <div id="div_form">
        <div class="div_contrato">Nome:</div>
        <div class="div_txt_contrato">
            <input type="text" name="nome" id="nome" class="textbox" value='<bean:write name="dto" property="nome"/>'>
        </div>
        <div class="div_bto_contrato">
            <input type="submit" name="gravar" value="Gravar" class="button" /> 
            <input type="reset" name="Voltar" value="Voltar" class="button" onClick="doBack()">
        </div>
    </div>
</html:form>

Desde já agradeço!

cade sua função?

Segue os js. 8)

<script type="text/javascript">
function exibe(id) {
	if(document.getElementById(id).style.display=="none") {
		document.getElementById(id).style.display = "inline";
	}
	else {
		document.getElementById(id).style.display = "none";
	}
}
</script>

Pior que passo o nome da DIV corretamente, não sei se essas tags do struts podem estar causando…

… duplicado

 if(document.getElementById(id).style.display== "none") {  

n deveria ser

 if(document.getElementById(id).style.display="none") { 

…??

[quote=guimoz] if(document.getElementById(id).style.display== "none") {

n deveria ser

 if(document.getElementById(id).style.display="none") { 

…??[/quote]

não

== (igualdade)
= (atribuição)

onde está o componente que chama essa ação?
e o script está dentro da tag do cabeçalho (header)?

Então o componente que chama essa função é um “select” no evento onclick.
O script está no header sim!

<html:select property="idPerfil" styleId = "idPerfil" value='${dto.perfil.idPerfil}' onclick="exibe('gridEmail');">
	<html:option value="-1">Selecione uma opção</html:option>
	<html:options collection="listPerfis" property="idPerfil" labelProperty="nome"/>
</html:select>

cara…
pelo jeito tá tudo certim…
rsrs
eu acho que deve ser o seguinte
no jsf, os id’s de alguns componentes mudam quando dentro de algum outro componente como h:form
por exemplo se vc tiver um form com o id = “formulario” e o h:inputText com o id=“texto” então na renderização o framework vai interpretar e colocar assim
h:inputText id=“formulario:texto” mas eu não sei se isso acontece com componentes html puro
verifique se não é isso que está acontecendo

Com certeza é algo referente ao <html:form>, as tags do struts devem estar mudando a identificação.
Pior que não tenho a menor idéia de como referenciar esse <div>, já que no código fonte aparece o

&lt;div id="nomeDadoPorMim"&gt; .... &lt;div&gt; 

Faz um teste disso sem ser com JSF

Até

[size=7]
Senhores(as)

Muito estranho, não mudei nada e agora foi!!! Segue o js e parte do jsp.

[code]
<script language=“JavaScript” type=“text/javascript”>
function doExibition(value){
alert(value);
if(value==1){
document.getElementById(‘gridCodigo’).style.display = “none”;
document.getElementById(‘gridEmail’).style.display = “inline”;
}else if(value==2){
document.getElementById(‘gridCodigo’).style.display = “none”;
document.getElementById(‘gridEmail’).style.display = “inline”;
}else if(value==3){
document.getElementById(‘gridCodigo’).style.display = “inline”;
document.getElementById(‘gridEmail’).style.display = “none”;
}
}

	&lt;/script&gt;

				&lt;html:form action="/undertaker/funcionario.do?method=doConfirm" focus="nome" styleId="searchform"&gt;
					&lt;input name="action" id="action" type="hidden" value="&lt;%=action%&gt;" &gt;
					&lt;input name="idFuncionario" id="idFuncionario" type="hidden" value='&lt;bean:write name="dto" property="idFuncionario"/&gt;'&gt;
					&lt;div id="div_form"&gt;
						&lt;div class="div_contrato"&gt;Nome:&lt;/div&gt;
						&lt;div class="div_txt_contrato"&gt;
							&lt;input type="text" name="nome" id="nome" class="textbox" value='&lt;bean:write name="dto" property="nome"/&gt;'&gt;
						&lt;/div&gt;
						&lt;div class="div_contrato"&gt;Perfil:&lt;/div&gt;
						&lt;div class="div_txt_contrato"&gt;
							&lt;html:select property="idPerfil" styleId = "idPerfil" value='${dto.perfil.idPerfil}' onchange="doExibition(idPerfil.value);"&gt;
								&lt;html:option value="-1"&gt;Selecione uma op&ccedil;&atilde;o&lt;/html:option&gt;
								&lt;html:options collection="listPerfis" property="idPerfil" labelProperty="nome"/&gt;
							&lt;/html:select&gt;
						&lt;/div&gt;

						&lt;div id="gridCodigo" style="display:none"&gt;
							&lt;div class="div_contrato"&gt;Código Vendedor:&lt;/div&gt;
							&lt;div class="div_txt_contrato"&gt;
								&lt;input type="text" name="idCorretora" id="idCorretora" class="textbox" value='&lt;bean:write name="dto" property="idCorretora"/&gt;'&gt;
							&lt;/div&gt;
						&lt;/div&gt;

						&lt;div id = "gridEmail" style="display:none"&gt;
							&lt;div class="div_contrato"&gt;Email:&lt;/div&gt;
							&lt;div class="div_txt_contrato"&gt;
								&lt;input type="text" name="email" id="email" class="textbox" value='&lt;bean:write name="dto" property="email"/&gt;'&gt;
							&lt;/div&gt;
						&lt;/div&gt;

						&lt;div class="div_contrato"&gt;Senha:&lt;/div&gt;
						&lt;div class="div_txt_contrato"&gt;
							&lt;input type="password" name="senha" id="senha" class="textbox" value='&lt;bean:write name="dto" property="senha"/&gt;'&gt;
						&lt;/div&gt;

						&lt;div class="div_bto_contrato"&gt;
							&lt;input type="submit" name="gravar" value="Gravar" class="button" /&gt; 
							&lt;input type="reset" name="Voltar" value="Voltar" class="button" onClick="doBack();"&gt;
						&lt;/div&gt;
					&lt;/div&gt;
				&lt;/html:form&gt;

[/code][/size]

Putz… puxa da memória q alguma coisa vc alterou!! rs

Mas o importante é q funcionou!!

:smiley: