Andrew Vanusi Andrew Vanusi - 1 year ago 90
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?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download