This question already has an answer here:
I have PHP code as in the following.
<?php
echo "<SCRIPT LANGUAGE='javascript'>add dd_Employee('".$id1."','".$fname1."',".$sal1.");</SCRIPT>";
echo "<SCRIPT LANGUAGE='javascript'>add dd_Employee('".$id2."','".$fname2."',".$sal2.");</SCRIPT>";
....
?>
...
And my JavaScript code contains
var details=new Array();
function addEmployee(id,fname,salary){
var temp=new Array(id,fname,salary);
details[details.length]=temp;
alert(temp);
}
function displayEmployee(){
for (var i=0;i<details.length;i++)
var temp_details=details[i];
//Display the id,name,sal
var id=temp_details[0];
var name=temp_details[1];
var sal=temp_details[2];
alert(id);
alert(name);
alert(sal);
}
Now the problem is whatever assigned by the PHP will visble only in AddEmployee
. Which means it is working fine. But inside displayEmployee
the value assigned by PHP will not work. Is there any flaw in my logic?
</div>