Forum Moderators: open
In php i create and array in javascript i populate that array in php write it out in javascript using a loop .
now my problem is that my javascript is not seeing the array
my problem area's : javascrip array
passing a variable from javascript to php
passing a variable from onchange to php ?
<?php
include "dbaconnect.php" ;
$i=1;
?>
<?
$l=0;
$k=1;
$m=507;
$sql4="SELECT * FROM country ORDER BY country";
$query4 = mysql_query($sql4);
while
($row4 = mysql_fetch_array($query4))
{
$i=$row4['country'] ;
#print "$i;";
$sql5="SELECT count(*) FROM city WHERE country='$i'";
$query5 = mysql_query($sql5);
$row5 = mysql_fetch_array($query5) ;
#$m = $row5[0] ;
$sql6="SELECT * FROM city WHERE country='$i'";
$query6 = mysql_query($sql6);
While(
$row6 = mysql_fetch_array($query6))
{
$z=$row6['city'];
#Echo $row6[city];
$cities[$l][0]=$i;
$cities[$l][$k]=$z;
$cities[$l][0] ="countrycity[$l][0] = $i\n";
$cities[$l][$k]="countrycity[$l][$k] = $z\n";
Echo $cities[$l][$k] ;
$k++;
#Echo $cities[$l][$k];
}
$k=1;
$l++;}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-GB">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>populate a select </title>
<script type="text/javascript">
function populateSelect(optionList, optionValue, optionText)
{
optionList[optionList.length] = new Option(optionText, optionValue);
}
function clearOptions(optionList)
{
for (i = optionList.length; i >= 0; i = i - 1)
{
optionList[i] = null;
}
}
function populateMySecondarySelect()
{
var myPrimarySelectList = document.myFormName.myPrimarySelect;
clearOptions(document.myFormName.mySecondarySelect);
type countrycity = new countrycity[210][20];
<? for ($country=0;$country<=210;$country++) { Echo $cities[$country][0] ; } ?>
for (a=0;a<=210; a=a+1 )
if (myPrimarySelectList[myPrimarySelectList.selectedIndex].value == "Albania")
{
{ populateSelect(document.myFormName.mySecondarySelect, "0", "Please select an A word:");
<? $sql7="SELECT * FROM city WHERE country='Albania'";
$query7 = mysql_query($sql5);
$row7 = mysql_fetch_array($query7) ;
for ($city=0;$city<=($row7[0]);$city++ ) ?>
{ populateSelect(document.myFormName.mySecondarySelect, "<? echo $cities[$country][$city] ; ?>", "<? echo $cities[$country][$city] ; ?>");
}
}
}
</script>
</head>
<body>
<form name="myFormName" method="post" action="#">
<h1>
<?Echo $cities[0][0] ;?> <? Echo $cities[0][1] ;?> Populate a Select
</h1>
<hr>
<noscript>
<p>
If you can see this message it means that your browser is not running JavaScript
</p>
</noscript>
<p>
countrycity[a][0]
<SELECT NAME="myPrimarySelect" onChange="populateMySecondarySelect()">
<?
$sql2 = "SELECT * FROM country ORDER BY country";
$result2 = mysql_query($sql2);
while ($myrow2 = mysql_fetch_array($result2)) {
print ("<option>$myrow2[country]</option>");
}
?>
</SELECT>
<br>
<br>
<select name="mySecondarySelect">
<option> </option>
</select>
</p>
</form>
</body>
</html>
<?
mysql_close($con) ;
?>