Ciao con firebub i value sono impostati bene, la cosa che mi fa piú rabbia è che non è la prima volta che lo faccio e ha sempre funzionato, ora con questo non ne vuole sapere proprio sicuramente ci sarà l'errorino ma non capisco proprio dove.
La pagine in questione e in questo link provvisorio link
È il campo di cui stiamo parlando è regione, ho impostato un alert che dovrebbe far apparire nella finestra il valore selezionato, ma nulla
qui di seguito il codice jquery
codice:
$(document).ready(function(e) { $.ajax({ url:"selector.php", data:"ric=1", success: function(data) { $("#regioni").html(data); } }); }); function selectProvincia() { var code = $("#regioni").val(); alert(code); $.ajax({ url:"selector.php", data:"ric=2&code="+code+"", success: function(data) { $("#provincie").html(data); } }); } function selectComune() { var code = $("#regioni").val(); $.ajax({ url:"function/selector.php", data:"ric=3&code="+code+"", success: function(data) { $("#provincie").html(data); } }); }
Qui il codice php che preleva il tutto
Codice PHP:
class selector { public $reg; public $pro; public $com; public $error; public function selReg() { $selectRegioni = mysql_query("SELECT * FROM istat_regioni ORDER BY nome_regione "); $this->reg .="<select name=\"regioni\" id=\"regioni\" onChange=\"selectProvincia()\">"; while($regioni = mysql_fetch_array($selectRegioni)) { $this->reg .= "<option value=\"$regioni[codice_regione]\">$regioni[nome_regione]</option>"; } $this->reg .="</select>"; $this->error = mysql_error(); } public function selPro($codPro) { $selectProvince = mysql_query("SELECT * FROM istat_province WHERE codice_regione = '$codPro' ORDER BY nome_provincia "); $this->pro .="<select name=\"province\" id=\"province\" onChange=\"selectComune()\">"; while($province = mysql_fetch_array($selectProvince)) { $this->pro .= "<option value=\"$province[codice_provincia]\">$province[nome_provincia]</option>"; } $this->pro .="</select>"; $this->error = mysql_error(); } public function selCom($codCom) { $selectComune = mysql_query("SELECT * FROM istat_comuni WHERE codice_provincia = '$codCom' ORDER BY nome_comune "); $this->com .="<select name=\"comune\" id=\"comune\">"; while($comune = mysql_fetch_array($selectComune)) { $this->com .= "<option value=\"$comune[codice_comune]\">$comune[nome_provincia]</option>"; } $this->com .="</select>"; $this->error = mysql_error(); } }
Per finire quest'ultimo script php funge da ponte
Codice PHP:
<?php include 'select.php'; if(@$_REQUEST['ric'] == 1) { $reg = new selector; $reg->selReg(); echo $reg->reg; echo $reg->error; } else if ( @$_REQUEST['ric'] == 2 ) { $reg = new selector; $reg->selPro($_REQUEST['code']); echo $reg->pro; echo $reg->error; }else if ( @$_REQUEST['ric'] == 3 ) { $reg = new selector; $reg->selCom($_REQUEST['code']); echo $reg->com; echo $reg->error; } ?>