-1
when the user chooses a certain option in select, another select will appear, ie if marital status is married the spouse will appear.
I need the value of select to pass to a variable, this variable will communicate with javascript and it will do the action of hide enter the code here
window.onload = function exibir($pegavalor){
var valor = $pegavalor;
if(valor == true)
document.getElementById('optionOculto').style.display = "block";
else if(valor == false)
document.getElementById('optionOculto').style.display = "none";
};
};
}
<select name="civil" id="civil" onchange="exibir($pegavalor,'optionOculto')">
<option value="0"<?=($pegavalor = 0)?> >
-- Selecione --
</option>
<option value="1" <?=($pegavalor = 1)?> >
Casado
</option>
<option value="2" <?=($pegavalor = 0)?> >
Solteiro
</option>
<option value="3" <?=($pegavalor = 0)?> >
União Estável
</option>
<option value="4" <?=($pegavalor = 0)?> >
Divorciado
</option>
<option value="5" <?=($pegavalor = 0)?> >
Outros
</option>
</select>
<?php
echo $pegavalor;
if($pegavalor == 1){
$pegavalor = true;}
else{
$pegavalor = false;}
?>
<div id="optionOculto">
Nome Conjuge <input type="text" name="n-conjug"/>
Valor da Renda <input type="text" name="v-renda"/>
Outras Renda <input type="text" name="o-renda"/>
</div>
It is necessary to pass a variable to collect the values of "value", select ID (civil status) and select ID (hidden), because I have many conditions like this, creating a js for each would be impossible
– DaniloAlbergardi
There’s some php in the middle, like so?
– rodorgas
I’m trying, it can’t be right rsrs, I don’t know much
– DaniloAlbergardi
I thought it was an error when copying the code, sorry. In fact, it is necessary to remove the parts
<? ... ?>
and add a System to the select’s Event "change".– rodorgas