Javascript excerpt does not work

0

I do not know what I'm doing wrong, maybe it can be simple, but it does not give me the expected result.

In creating the html component:

 <li class="dropdown notifications-menu">

                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    <i class="fa fa-university"></i>
                    <span class="label label-warning">{{count($empresas)}}</span>
                </a>

                <ul class="dropdown-menu">

                    <li class="header">Você pode emitir recibo para {{count($empresas)}} empresas</li>

                    <li>

                        <ul class="menu">

                            @foreach($empresas as $e)
                                <li><!-- start notification -->
                                    <a name="itemlista" id="{{$e->id}}"
                                       onclick="guardaIdSplit({{$e->id.":".$e->name}})" href="#">
                                    <i class="fa fa-industry text-aqua"></i> {{$e->name}}
                                </a>
                            </li><!-- end notification -->
                            @endforeach

                        </ul>

                    </li>

                </ul>

            </li>

In the script:

 function guardaIdSplit(empresa) {

                    var newArray = empresa.split(":");

                    var id = newArray[0];
                    var name = newArray[1];

                    $("[name=itemlista]").removeClass("text-green");
                    $("[name=itemlista]").addClass("text-black");

                    window.localStorage.setItem('emitente_id', id);

                    $("#" + id).removeClass("text-aqua");
                    $("#" + id).addClass("text-green");

                    $("#emitenteSelect").text(""+name);

                }

It should be close to this image:

    
asked by anonymous 17.08.2017 / 01:21

1 answer

1

Its JS function is without syntax failures, so the problem is probably in the call. Analyzing by what you put above:

Your code: onclick="guardaIdSplit({{$e->id.":".$e->name}})"

It should render: onclick="guardaIdSplit(1:Teste)"

Being that you should pass a String: onclick="guardaIdSplit('1:Teste')"

Porting the solution should be: onclick="guardaIdSplit('{{$e->id.":".$e->name}}')"

    
17.08.2017 / 01:41