pass parameters of evnto onclick to javascript function

0
//Obtener los permisos asignados al usuario
$permisosAsignados = $permisos->listarPermisosMarcados($cedula,$id_item);
//mostramos los permisos si estan o no marcados
while ($reg = $permisosAsignados->fetch_object()){
    $html = '<li>
    <a href="#"  data-toggle="dropdown" class="dropdown-toggle">
    <span>'.$reg->nombre.'</span>
    <span class="caret"></span>
    </a>
    <ul class="dropdown-menu" >';
    $permisosAsignados1 = $permisos->listarsubMenuPermiso($reg->id_menu);

    while ($reg1 = $permisosAsignados1->fetch_object()){
        $html = $html .'
        <li >
        <a href="#" **onclick="cargarDiv('.$reg1->url.');">'.$reg1->nombre.'</a>**
        </li>';
    }
    $html = $html . '</ul>
    </li>';
    echo $html;
} 

on this line

<a href="#" onclick="cargarDiv('.$reg1->url.');">'.$reg1->nombre.'</a>

I load a data from the database $reg1->url to be sent to a JavaScript function, but it does not work, this variable $reg1->url has a path of a file. but when I send numbers if you send the parameter to the function I hope you can help me thanks

    
asked by Rene Tabango 28.08.2018 в 00:32
source

1 answer

0

try escaping the quotes as follows: \ '

The line would look like this:

<a href="#" **onclick="cargarDiv(\''.$reg1->url.'\');">'.$reg1->nombre.'</a>
    
answered by 28.08.2018 в 14:37