Make a form appear when we select some option

Submitted by sayasuhendra - 10 years ago

Sub Form, Cascade Form, Form Inside Form

// Form Create

        <div class="form-group">
            {{ Form::label('layanan', 'Layanan:', ['class' => 'col-sm-3']) }}
            <div class="col-sm-9">
            {{ Form::select('layanan', ['VSAT' => 'VSAT', 'ADSL' => 'ADSL', 'Dedicated' => 'Dedicated', 'Layer 2' => 'Layer 2', 'IP Transit' => 'IP Transit', 'Hosting' => 'Hosting', 'Collocation' => 'Collocation'], null, ['class' => 'form-control']) }}
        </div></div>
        <div class="form-group">
            <div class="col-sm-9 pull-right">
            {{ Form::hidden('username', null, ['class' => 'form-control', 'placeholder' => 'username', 'id' => 'username']) }}
        </div></div>
        <div class="form-group">
            <div class="col-sm-9 pull-right">
            {{ Form::hidden('password', null, ['class' => 'form-control', 'placeholder' => 'password', 'id' => 'password']) }}
        </div></div>
        
// Jquery 

<script>
    $('#layanan').change(function() {
        if ($(this).val() === 'ADSL') {
            $("#username").removeAttr( "type" );
            $("#password").removeAttr( "type" );
        }
        if ($(this).val() !== 'ADSL') {
            $("#username").attr( "type", "hidden" );
            $("#password").attr( "type", "hidden" );
        }
    });
</script>