Forum Moderators: coopster
Here's the array:
$i=0;
do{
$arrayAssignments[$i] = " " .$row_getAssignment['empNo'] ."-" .$row_getAssignment['projectID'];
$i++;
}
while ($row_getAssignment = mysql_fetch_assoc($getAssignment));
I am then trying to access it later inside of javascript here:
for (i=0;i<=50;i++)
{
if(<?php $arrayAssignments[$i]?> == document.form3.empNo.value+"- "+document.form3.projectID.value )
{
alert('The resource you selected is already assigned to this project');
return false;
}
}
Does anyone know what I'm doing wrong?
Thanks guys
So basically it's like you getting the output and typing it in by hand. That would work for numerics but strings aren't much more difficult.
I just looked in my big javascript book and it's talking about declaring an array using a "streamlined syntax" that looks like this:
aryvbl = ["apple","grape","blueberry"]
You can make php mimic that with implode. If you have a php array that functionally has the content above:
$arystring = implode('","',$aryvbl);
gets you this:
$arystring = apple","grape","blueberry
That's really close to what you want, but you need some quotes on the ends as well as the brackets:
$arystring = '["' . implode('","',$aryvbl) . '"]';
Now
$arystring = ["apple","grape","blueberry"]
and make it part of the document:
echo 'var arystring=' . $arystring;
Then in the other part of your javascript, you'll use
if(arystring[i] == document.form3.empNo.value+"- "+document.form3.projectID.value )