1
function teste(valor)
{
if( valor=="novo" )
{
document.getElementById('quantdependente').style.display = 'block';
}
else
{
document.getElementById('quantdependente').style.display = 'none';
}
}
#quantdependente {
display: none;
}
<html>
<body>
<form id="formulario" name="formulario" action="montadependente.php" method="post">
<select name="teste" id="teste" onchange="teste( this.value );">
<option value="1">1</option>
<option value="2">2</option>
<option value="novo">novo</option>
</select>
<div id="quantdependente" name="quantdependente">
<input type="number" value="" step="1">
</div>
<input type="submit" name="btenviar" value="enviar">
</form>
</body>
</html>
Don’t understand the question? The code apparently works. You can add a detailed description of your problem?
– Augusto Vasques
@Augustewhat when testing code in Chrome error occurs
Uncaught TypeError: teste is not a function
, because he created an element with theid="teste"
, what conflicts with the called functionfunction teste(valor)
, as it is common for browsers to use DOM Ids as global object variableswindow.
, as explained in https://answall.com/q/123098/3635– Guilherme Nascimento