OiO.lk Blog PHP Why the following simple function does not work in HTML?
PHP

Why the following simple function does not work in HTML?


I have two files, first file is a JavaScript file and in this file I have a function that is expected to print "Hello World", and the second file is a php file and in this file I tried to call the function that exists in JavaScript file but that does not work.

Here is in the following the code that exists in the JavaScript file:

var para_1 = "Hello World";
function para1() {document.write(para_1);}

Here is the image of JavaScript file

Here is in the following the code that exists in php file:

<html>
<script src="JavaScript2/Variables2.js"></script>

<head>
    <title>ABC</title>
</head>

<body>

<script>
 para1();
</script>

</body>

</html>

Here is the image of php file

but after I run the php file, I didn’t get "Hello World" in the output. See this image: (Image)

I know it’s simple to type "Hello World" in the php file, but I want to know how to use a function from JavaScript file, so what is the problem of the code?



You need to sign in to view this answers

Exit mobile version