Andrew Vanusi Andrew Vanusi - 7 months ago 52
PHP Question

Display none not working Laravel

I have a condition, if active is checked then it'll display a text form.

This is my view form code:

<div class="form-group">
{{ Form::checkbox('active', 0,null, array('id' =>'active_check','class' => 'active_check')) }}
<div id ="join_date" class="form-group" style="display: none;">
<label>Join Date:</label>
<div class="input-group">
{!! Form::text('join_date', null, array('class' => 'form-control datetimepicker' )) !!}

Here is my jQuery toggle and check condition code so far:

$('#active_check').click(function() {
$('#join_date').find('input[type="text"], textarea').val('');
var activeCheck = $('checkbox[name="active_check"]');
function checkActive(select) {
if (select.val() == 0) {
} else {

The issue is when it is first loaded the join_date form doesn't hide. I need to toggle the checkbox to hide it. Any idea?


Try this simple logic:

if($('#active_check').is(':not(":checked")')) {//test if active_check is not checked 
 $('#join_date').hide();//hide it
$('#active_check').click(function() {
    $("#join_date").toggle();//toggle it