SeroS's avatar
Level 1

Cascading Dropdown list

Hello, i have 2 tables one called "proveedores" and another one called "clientes"; both tables have the same field called "nombre". I want to populate the second dropdown list with all the ítem on the field "nombre" of the database that the user choose on the first dropdownlist, can you help me, cause i'm new at this and i know that i have to use a java script or something like it. thanks in advance.

Here is what i have on the form.blade.php

<div class="form-group">
    {!! Form::label('tipo_empresa','Tipo de Empresa: ') !!}
    {!! Form::select('tipo_empresa',
                      array('Cliente' => 'Cliente', 'Proveedor' => 'Proveedor'),
                      null,
                      ['class'=>'form-control']
    ) !!}
</div>
<div class="form-group">
    {!! Form::label('nombre','Nombre de la empresa: ') !!}
    {!! Form::text('nombre',null,['class'=>'form-control']) !!}
</div>

Here is create.blade.php


@extends ('layouts/app')

@section('content')

<h1>Ingrese el nuevo Contacto</h1>

<hr/>

{!! Form::open(['url' => 'contactos']) !!}

  @include('contactos.form',['submitButtonText' => 'Añadir Contacto'])

{!! Form::close() !!}

  @include('errors/list')

@stop

here is the controller

public function create()
    {

      return view('contactos.create');
    }


    public function store(contactorequest $request)
    {

      contacto::create([
        'user_id'=> Auth::user()->id,
        'tipo_empresa'=> request('tipo_empresa'),
        'empresa_id'=> request('empresa_id'),
        'nombre'=> request('nombre'),
        'sector'=> request('secotr'),
        'telefono'=> request('telefono'),
        'interno'=> request('interno'),
        'mail'=> request('mail'),
        'celular'=> request('celular'),
        'localidad'=> request('localidad'),
        'observaciones'=> request('observaciones'),
      ]);

      session()->flash('message','Contactos creado exitosamene');

      return redirect('contactos');

    }
0 likes
3 replies
SeroS's avatar
Level 1

Thanks for the help, but what i mainly want its to know how to change the data on the second select when the first one change, if you can point me a guide or something that show me how to make that.

Swaz's avatar

That part could go in app.js, or at the bottom of the page within a <script> tag.

<script>
    $(function() {
        $("#series").chained("#mark");
    });
</script>
1 like

Please or to participate in this conversation.