I created a file called “page.php” with the below code.
<!DOCTYPE HTML>
<html>
<body>
<?php
require 'form.php';
?>
<a href="#" onclick="call_popup('form_container')">Click this link!</a>
</body>
</html>
And I created another file “form.php” with the below code:
<script type="text/javascript">
function call_popup (container_id) {
var id= document.getElementById(container_id);
alert(id);
}
</script>
<div id="form_container">
<form>
<input type="text" />
<input type="button" value="submit" />
</form>
</div>
I am trying to call the “call_popup(container_id)” function in “page.php” which is defined in “form.php”. When I click the “Click this link!” of the anchor tag it gives an error saying call_popup('form_container') not found!
Where did I go wrong?
You need to add this in the beginning of “page.php”:
But I am not sure that works with JavaScript functions..
Try create a JavaScript file, “file.js”, and reference it in two PHP files: