Laravel text form onchange

David Abadi from

I have a form and depending if a text input is filled, another one will appear.

My HTML

<div class="col-sm-3">
    <div class="form-group">
        {{ Form::label('personal_extra', 'Extra (nombre):', ['class' => 'control-label']) }}
        {{ Form::text('personal_extra', null, [ 'onchange' => "personal_extra();", 'class' => 'form-control', 'id' => 'personal_extra']) }}
    </div>
</div>
<div class="hidden" id="personal_extra_cantidad">
    <div class="col-sm-3">
        <div class="form-group">
            {{ Form::label('personal_extra_cantidad', 'Extra (cantidad):', ['class' => 'control-label']) }}
            {{ Form::number('personal_extra_cantidad', null, ['class' => 'form-control', 'min' => '0']) }}
        </div>
    </div>
</div>

My script

function personal_extra() {
    var x = document.getElementById('personal_extra').value;
    var y = document.getElementById('personal_extra_cantidad');
    if (x == null) {
        y.className = "hidden";
    } else {
        y.className = "visible";
    }
}

Is this the correct format to do it? Should I be doing something else?

javascript laravel laravel-5