Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Javascript array


Message #1 by "Mário Ramos" <mjpr@f...> on Mon, 29 Apr 2002 18:02:50
Hi! 
This is a javascript question with a bit of php-mysql in it.

I have a select box and 2 textfields.

The select box is populated by a mysql query. And associated to it a 
onchange funtion.

The onchange funtion is like:
function goGetThem2()
{
  var dis=document.cria_inq.Disciplina.options
[document.cria_inq.Disciplina.selectedIndex].id;
  document.cria_inq.CodDisciplina.value=dis;
}

that copies the id of the selected index of the select box to a input 
textfield (the first one).

And then I have another mysql query that fills a javascript array:

$sql = "select CodPlano,disciplinasplano_arq.CodDisciplina,DesDisciplina 
from disciplinas_arq,disciplinasplano_arq
where disciplinas_arq.CodDisciplina= disciplinasplano_arq.CodDisciplina";

$result = mysql_query($sql);

$number = mysql_numrows($result);
  
$i = 0;

if ($number == 0)
print "Error - No recordss";
elseif ($number > 0)
{
echo "<script language='javascript'>\n";
echo "myarray = new Array($number);\n";
while ($i < $number) 
{
$text = mysql_result($result, $i, "CodPlano");
//print "$text";
echo "myarray[$i]=$text;\n";
$i++;
}
}
echo "\n</script>";
mysql_free_result($result);
mysql_close();

What I want to do is, based on the selected option, it prints in the 2nd 
textfield the result of a query relation. I had to do something like this 
because the select box only has 2 things we can use: "id" and "value".

Any ideas?

  Return to Index