Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    3

    Ajax - Probelma con select dinamica

    La prima select 'nation' popola dinamicamente la seconda select. Lo script pare funzionare, e la seconda select è popolata con successo. Quando però invio il modulo, i valori della seconda select non passano.

    Ho provato ad inviare il modulo con get: non appare niente (regione=...), come se il contenuto del file esterno findregione.php non venisse letto. Cosa non va???


    ************* il codice javascript **************

    function getXMLHTTP() { //fuction to return the xml http object
    var xmlhttp=false;
    try{
    xmlhttp=new XMLHttpRequest();
    }
    catch(e) {
    try{
    xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e){
    try{
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e1){
    xmlhttp=false;
    }
    }
    }

    return xmlhttp;
    }







    function getState(name) {

    var strURL="findregione.php?nation="+name;
    var req = getXMLHTTP();

    if (req) {

    req.onreadystatechange = function() {
    if (req.readyState == 4) {
    // only if "OK"
    if (req.status == 200) {
    document.getElementById('regiondiv').innerHTML=req .responseText;
    } else {
    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    }
    }
    }
    req.open("GET", strURL, true);
    req.send(null);
    }
    }



    **************** il codice html con le due select ****************

    <select name="nation" id="nation" onChange="getState(this.value)">
    <option >Select country</option>
    [...]
    </select>

    <div id="regiondiv" name="regiondiv">
    <select name="regione">
    <option>Select region</option>
    </select>
    </div>

    ************* il file esterno findregione.php *******************

    <? $nation=$_GET['nation'];
    include_once 'connections.php';
    dbConnect();
    $query="SELECT [...]";
    $result=mysql_query($query);
    ?>
    <select name="regione">
    <option>Select region</option>
    <? while($row=mysql_fetch_array($result)) { ?>
    <option value="<?=$row['nomeregione']?>"><?=$row['nomeregione']?></option>
    <? } ?>
    </select>

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    3

    Funge solo con IE

    Ho testato lo script con tutti i brwser. Va con IE, non funge in Firefox e Safari...

  3. #3
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Prova ad inserire un alert per vede cosa scrive il response

    if (req.status == 200) {alert(req.responseText);}

    da errori su firefox (nella barra strumenti > console degli errori)
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.