Online Tutorials & Training Materials | STechies.com
Register Login
Advertisement

How to call a JavaScript function from PHP

|| 0

How to call a JavaScript function from PHP
Stechies

A function is a code block to execute a particular task. To perform that particular task get executed one have to call it.

Example of function

function func_call(par1, par2){
return par1+par2;  // this function will return the Addition of two parameter.
}

You can call a function of Java Script through PHP, but you can't execute it.

Call Function

The block of code inside the function, (I) a user calls of click a button.(II) automatically executed

Return Function

As the java scripts reached to a return statement execution of the function is stopped and the function  return result to the called.

PHP is a server scripts, java scripts runs on client side, runs on the browser. The browser cannot detect PHP script since java script output merge PHP output.
So that you cannot call java script using PHP / from PHP, but you can include in the output from java script.

Example

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Call JS Function</title>
    <script type="text/javascript">
    public function jsFunction(){
        alert('Hi This is Test Function alert');
    }
    </script>
</head>

<body>
<?php 
	echo '<script type="text/javascript">jsFunction();</script>'; 
?>
</body>
</html>

 


Advertisement
Advertisement
Advertisement