lo so che posso chiudere i tag php, il fatto è che stampando con php i codici, verranno elaborati prima in quanto php è lato server e la risposta sarà sicuramente più rapida rispetto all'elaborazione lato client...
cmq sto riadattando l'esempio del link che ho citato sopra inserendo solo il php per generare l'array e la lista select, ma mi da un problema con "db.lenght" nel ciclo FOR e non capisco il perché...posto il nuovo codice sperando di limitare la discussione solo a javascript (come mi è stato segnalato dal moderatore)
Codice PHP:
<script type="text/javascript">
var regiondb = new Object()
<?php
include 'dbconnect.php';
/**********************************************/
// GENERAZIONE OBJECT() DA DATABASE CON CICLO PHP
/**********************************************/
$querycta = mysql_query("SELECT * FROM ct_area");
$arraypippo = "";
while ($row1 = mysql_fetch_assoc($querycta))
{
$arraypippo .= "regiondb['".$row1['nome_area']."'] = [";
$queryctsa = mysql_query("SELECT * FROM ct_sotto_area WHERE area = ".$row1['ID_area']);
$counter = 0;
while ($row2 = mysql_fetch_assoc($queryctsa))
{
$counter ++;
$tot = mysql_num_rows($queryctsa);
if ($counter < $tot) {
$arraypippo .= "{value: ".$row2['ID_sottoarea'].", text: '".$row2['nome_sottoarea']."'},";
}else{
$arraypippo .= "{value: ".$row2['ID_sottoarea'].", text: '".$row2['nome_sottoarea']."'}";
}
}
$arraypippo .= "]; ";
}
echo $arraypippo;
?>
/**********************************************/
// FUNZIONE SELEZIONE E GENERAZIONE SECONDA SELECT
/**********************************************/
function setCities(chooser) {
var newElem;
var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
var cityChooser = chooser.form.elements["città"];
while (cityChooser.options.length) {
cityChooser.remove(0);
}
var choice = chooser.options[chooser.selectedIndex].value;
var db = regiondb[choice];
newElem = document.createElement("option");
newElem.text = "Seleziona una città:";
newElem.value = "";
cityChooser.add(newElem, where);
if (choice != "") {
for (var i = 0; i < db.length; i++) {
newElem = document.createElement("option");
newElem.text = db[i].text;
newElem.value = db[i].value;
cityChooser.add(newElem, where);
}
}
}
</script>
/**********************************************/
// FORM CON LIST BOX
/**********************************************/
<form name="form">
Invia la richiesta a:
<select name="continente" onchange="setCities(this)">
<option value="" selected="selected">Seleziona un continente:</option>
/**********************************************/
// COMPILAZIONE DELLE OPTION CON CICLO PHP
/**********************************************/
<?php
$querycta = mysql_query("SELECT * FROM ct_area");
while ($row = mysql_fetch_assoc($querycta))
{
echo "<option value = ".$row[nome_area]." >" .ucfirst($row[nome_area]). "</option>";
}
?>
</select>_
<select name="città">
<option value="" selected="selected">Seleziona una città:</option>
</select>
</form>
Spero di aver circoscritto la richiesta di aiuto ad un solo argomento
grazie a tutti per il tempo dedicatomi