Tried below but only echoes notes array in View Source...
//create string for javascript assoc array format. "key1:value1", "key2:value2", ........
for($i=0; $i < sizeof($id_array); $i++)
{
$javascript_array[$i] = '"'.$id_array[$i].'":"'.$type_array[$i].'"';
$javascript_array1[$i] = '"'.$id_array[$i].'":"'.$type1_array[$i].'"';
}
?>
<script language="Javascript">
var notes = new Array();
var notes2 = new Array();
<?php
echo php2js_array('notes', $javascript_array);
echo php2js_array('notes2', $javascript1_array1);
?>
document.write(notes[0]);
document.write(notes2[0]);
function change(id)
{
document.getElementById('inv_type_note').innerHTML = notes[id];
document.getElementById('inv_type_note2').innerHTML = notes2[id];
}
</script>
<?php
function php2js_array($js_arr_name, $php_arr)
{
$str = '';
foreach ($php_arr as $key => $val) {
if (is_int($key)) {
$str .= $js_arr_name . '[' . $key . ']';
} else {
$str .= $js_arr_name . '["' . $key . '"]';
}
if (is_int($val) || is_float($val)) {
$str .= '=' . $val . ';' . "\n";
} else {
$str .= '="' . $val . '";' . "\n";
}
}
return $str;
}
?>
What I'm trying to achieve is this...
1/ Get data from Database
2/ Assign data to arrays
3/ When user makes a selection from select menu two ther textfields will be populated with the data from two relevant arrays.
Is there a simpler way of doing this?