1
The Form has a checkbox
that when selecting shows an input that is hidden.
It is working correctly, when I enter the page the input is hidden
and is only visible when I select the checkbox
, as I show:
<div class="table-responsive">
<label for="IniciarTarefa">Tarefa a Par</label>
<input type="checkbox" name="check" id="check" value="Sim"/>
<div class="form-group input-group input-group-lg">
<span class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
</span>
<select class="form-control" name="Acompnhante" id="Acompnhante" style="display:none" required="" placeholder="Acesso">
<option></option>
<?php
$sql = "SELECT * FROM raddb.usuarios ORDER BY nome ASC";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo '<option value="'.$ln['id'].'">'.$ln['nome'].'</option>';
}
?>
</select>
</div>
</div>
Script:
$("#check").click(function(){
if($(this).val()=="Sim"){
$("#Acompnhante").css("display","block");
$(this).val("false");
}
else{
$("#Acompnhante").css("display","none");
$(this).val("Sim");
}
});
The problem arises when I enter in the database and with AJAX clean this input
and the checkbox
within the function success
, in this way:
$.ajax({
url: './insertarefa',
type: 'POST',
cache: false,
data: dadosajax,
error: function(){
},
success: function(result)
{
$('#check').attr('checked', false);
$("#Acompnhante").val("");
}
});
After clearing the two fields with AJAX, when I select the checkbox
hides the input
, changes the process, because when I clean the two fields the input
is visible. How can I solve?
Wouldn’t it be because it was missing put
$("#Acompnhante").css("display","none");
within thesuccess: { }
?– hugocsl
@hugocsl with this line of code when cleaning puts the input back
hidden
, but even exchange the process, only opens when I withdraw the selection– Bruno