Skip to content
Advertisement

Can you call JavaScript function from PHP loop?

I am wounding if I can do this, as I am trying this from last 2 days but no success.

I want to run JavaScript function from PHP

PHP example

JavaScript

JavaScript

JavaScript

I am trying to generate a page which print loop number one by one.

But I got error jfun is not defined.

What I can understand my JavaScript function is not ready at the time of PHP execution. Is there any way round, like running the PHP loop when DOM/Page is ready so that the JavaScript function will be ready that time, or any other way round.

Advertisement

Answer

You have to define that function before calling it

http://sandbox.phpcode.eu/g/15b02.php

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement