How to disable a field that is inside a hidden div so it does not work on submitting the form
Exemp: In this script, when I submit the form, the fields that are hidden are sent, but this field 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>