Can we do
var name = <?PHP $_POST["name" ?>
on .js file?
So I want to get the $_POST value of php to make use of it in my javascript, because php lack of document.getElementById("id");
Can we do
var name = <?PHP $_POST["name" ?>
on .js file?
So I want to get the $_POST value of php to make use of it in my javascript, because php lack of document.getElementById("id");
As i mentioned in the comment you can use a global variable to store the value and that variable can be used in the js file:
<html>
<head>
<script>
var name = '<?php echo $_POST["name"]; ?>'; // <---should be wrapped in quotes
</script>
<script src="jsfile.js"></script>
</head>
<body></body>
</html>
Now in the js file you can make a reference to this variable:
var user = name; // window.name;
no but you can make javascript file like javascript.php and put the following like on top of file
header("content-type: application/x-javascript");
and write javascript code in this file also then php code