Page 1 of 1

accessing a php declared array in javascript

Posted: Fri Oct 04, 2002 4:08 am
by coolen
Hi,

is it possible to access an array declared in php in javascript ??

if so How ?



$allClasses = array();

echo '<td><input type="text" name="new_class_name" maxlength=64 size=20 onchange=checkNewName($allClasses)> </td>';

-----

<script language="JavaScript">
function checkNewName(a){
document.write("length: ",a.length);
}
</script>

Posted: Fri Oct 04, 2002 4:52 am
by volka
please read Sticky: Before Post Read: Frames, JavaScript, and PHP Overview

you might output the content of the array to the document in a way that it can be access by javascript on the client, i.e.

Code: Select all

&lt;?php
$phpArrary = array();
....
?&gt;
...
&lt;script language="JavaScript"&gt;
var jsArray = new Array(&lt;?php echo implode(',', $phpArrary); ?&gt;
....