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

170
Vistas
Is it possible to write javascript function inside of php code?

I mean like

<?php echo "<script> javscript_function(<?php echo "$php_number_variable"; ?>); </script>" ?>

The $php_number_variable would be a number value from other php file.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Yes that's entirely possible. Basically all that happens here is the value which is echoed by PHP gets embedded in the JS and the whole JS block is then passed to the browser, which runs it - effectively the same as if you'd hard-coded the value instead of echoing it.

The issue you'll have with this specific code is that you can't echo within an echo...instead just concatenate the value into the string you're already building!

e.g.

<?php echo "<script> javscript_function(".$php_number_variable."); </script>"; ?>

Or, since you're using double-quote strings, the variable can be interpolated directly:

<?php echo "<script> javscript_function($php_number_variable); </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