Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

261
Vistas
Sending php array to a javascript function with button onclick in html

Maybe it was a little confusing.

I have a datatable. In this datatable, there is an edit button at the end. Clicking on the edit button opens a modal. I want to pass the data in this datatable to the modal. I can send it as a single variable, but when I want to convert the data to an array and throw it away, I get an error.

My table:

<td><input type="text" value="<?= $datt['a']; ?>" id ="a" class="form-control"/> </td>
<td><input type="text" value="<?= $datt['b']; ?>" id ="b" class="form-control"/> </td>
<td><input type="text" value="<?= $datt['c']; ?>" id ="c" class="form-control"/> </td>  
<? $arry = array(
"a" => $datt['a'],
"b" => $datt['b'],
"c" => $datt['c']);  ?>
<td><button id="updd" class="btn btn-success updd" data-toggle="modal" data-target="#updd" onclick="show_fun(<?= $arr ?>)">Edit</button></td>

JS function:

function show_fun(datt){
$(document).on("click", ".updd", function (e) {
 var obj = datt;

 console.log(datt);

});

Result:

Array() { [native code] }

I also sent the Array with json_encode.

I tried

onclick="show_fun(<?= $arr ?>)"

instead of

onclick="show_fun(<?= json_encode($arr) ?>)"

Result:

undefined

How can I send data to modal?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You don't need inner click listener. In HTML:

<button ... onclick="show_fun(<?= json_encode($arr); ?>);" />

In JS:

function show_fun(dat) {
 console.log(dat);
}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda