manamino
12-20-2005, 05:55 PM
hi can u help me to pass php values to javascript array,
actually I have many drop down boxes
I need onchange of one of them to change the values of the others according to the value of the first one
and since I dont need to submit the form to take the values and use them in php , I tried at the first of my program to put all the data in javascript arrays and then onchange I use javascript function to search for my values. this is a logical solution but it is not working with me, can u find the problem
this is my program:
search.php
<?php
$db = mysql_connect('localhost','root', 'memo1982');
mysql_select_db ("collab1",$db);
$sql=mysql_query("select * from student",$db);
?>
<script language='javascript'>
function lolo()
{
p=0;
var id=new array();
var fname=new array();
var lname=new array();
var gender=new array();
var level=new array();
var type=new array();
<?
$sql1=mysql_query("select * from sanction s, student st, officer o where s.Id=st.Id and s.Oid=o.Oid",$db);
while($row = mysql_fetch_array($sql1, MYSQL_NUM))
{?>
id[p]=<?=$row["Id"]?>;
p=p+1;
<?
}?>
document.write(p); //i made this one only to see if the function is working but it is not working
}
</script>
it is not even understand the arrays, can u help me work with arrays and solve my problem?
actually I have many drop down boxes
I need onchange of one of them to change the values of the others according to the value of the first one
and since I dont need to submit the form to take the values and use them in php , I tried at the first of my program to put all the data in javascript arrays and then onchange I use javascript function to search for my values. this is a logical solution but it is not working with me, can u find the problem
this is my program:
search.php
<?php
$db = mysql_connect('localhost','root', 'memo1982');
mysql_select_db ("collab1",$db);
$sql=mysql_query("select * from student",$db);
?>
<script language='javascript'>
function lolo()
{
p=0;
var id=new array();
var fname=new array();
var lname=new array();
var gender=new array();
var level=new array();
var type=new array();
<?
$sql1=mysql_query("select * from sanction s, student st, officer o where s.Id=st.Id and s.Oid=o.Oid",$db);
while($row = mysql_fetch_array($sql1, MYSQL_NUM))
{?>
id[p]=<?=$row["Id"]?>;
p=p+1;
<?
}?>
document.write(p); //i made this one only to see if the function is working but it is not working
}
</script>
it is not even understand the arrays, can u help me work with arrays and solve my problem?