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

145
Vistas
Try to generate a post method javascript links

I built a JAVASCRIPT into a PHP file that creates links to create links with the POST method, unfortunately it doesn't work, what am I doing wrong? which quotation marks should I choose in javascript?

echo '<form name="' . $i . '" method="post" action="?q=' . $query . '"><button type="submit" class="button" name="' . $i . '" value="' . $i . '">' . $i . '</button></form>';
echo '<script>
var button = document.querySelector(`form[name="` . $i .`"] > button`);
button.addEventListener(function() {
  document.querySelector("form[name="` . $i .`"]").submit();
});
</script>';
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use \' (backlash followed by ').

See this link where I tested it: https://onlinegdb.com/FF_Um4YdS

<?php

// random data for test
$i = "random-form";
$query = "nothing";


echo '<form name="' . $i . '" method="post" action="?q=' . $query . '"><button type="submit" class="button" name="' . $i . '" value="' . $i . '">' . $i . '</button></form>';
echo '
<script>
    var formButton = "form[name=\''. $i .'\'] > button";
    var button = document.querySelector(formButton);
    button.addEventListener(function() {
        document.querySelector("form[name=\'' . $i .'\']").submit();
    });
    </script>';

?>
about 4 years ago · Juan Pablo Isaza 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