Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda