Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!