1
How to disable a field that is inside a hidden div to not work when sending the form
Example: in this my script below when sending the form is also sent the fields that are hidden, but these fields should only be sent when they are shown
how to fix this?
function Mudarestado(el) {
var display = document.getElementById(el).style.display;
if(display == "block")
document.getElementById(el).style.display = 'none';
else
document.getElementById(el).style.display = 'block';
}
<form action="teste.php" method="GET">
Habilitar
<input type="checkbox" onclick="Mudarestado('minhaDiv')" class="valores" name="choice" value="200" /><br/>
<br><br>
Campo 1 :<input type="text" name="id" value="Ola" />
<input type="text" name="id" value="Ola2" />
<br><br>
<div id="minhaDiv" style="display: none;">
Campo 2 :<input type="text" name="id" value="Ola" />
<input type="text" name="id" value="Ola2" />
</div>
<input type="submit" value="Entrar" />
</form>
Will you use them again? if not just remove them instead of hiding
– Felipe Duarte
Hello... Yes I will use it according to need the checkbox is for this
– Fabio Henrique