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

367
Vistas
Pass javaScript variable to php or workaround for just php

I'm trying to get a JavaScript variable to php without refreshing the page or submitting the form. I think my problem is that php is on the server side. I have a button that's set in a php echo...

<input type='button' value='Edit' name='editbtn' onmouseup='reply_click(this.id)' onclick='edit()' id = '" . $row['id'] . "'

This button works correctly. I didn't provide all the code surrounding it, just the part in question. I can inspect the button element in the browser and the "id" shows the correct id number.

Next I'm using some test JavaScript in an effort to get the id to php with having to refresh the page or submit the form.

echo "<script type='text/javascript'>
        function reply_click(clicked_id){
            var selid = clicked_id;
            alert(selid);
            document.writeln(selid);        
        } </script>";

This code works. I get the correct id to show in an alert or document.writeln. The problem comes when I try to set this to a php variable like this...

$testid = "<script type='text/javascript'>document.writeln(selid);</script>";
echo $testid;

$testid returns nothing.

Is there a way to do this or is there a workaround using only php? I need to do this without submitting the form or refreshing the page. Is that possible? The end goal is to create another MySQL statement using that id value. For example: SELECT * FROM table WHERE id = the $testid from JavaScript.

Thank you!

about 4 years ago · Santiago Trujillo
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