0

我有一个通过 ajax 从数据库中获取的级联下拉列表。该列表加载但它没有发布到数据库,也没有看到后面的代码。

function getXMLHTTP() { //function 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 getCity(stateid)
{
    //alert(stateid);
  var strURL="findCity.php?state="+stateid;
  var req = getXMLHTTP();
  if (req)
  {
    req.onreadystatechange = function()
    {
      if (req.readyState == 4) // only if "OK"
      {
        if (req.status == 200)
        {
          document.getElementById('citydiv').innerHTML=req.responseText;
        } else {
          alert("There was a problem while using XMLHTTP:\n" + req.statusText);
        }
      }
    }
    req.open("GET", strURL, true);
    req.send(null);
  }
}

和php文件

<? $state=$_GET['state'];
    $link = mysql_connect('localhost', '', ''); //change the configuration if required
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('a'); //change this if required
    $query="select FOR_CODE,FOR_DESC from maruti_city where FOR_STAT_CODE='{$state}' order by FOR_DESC";
    $result=mysql_query($query);?>
    <select name="city" onchange="getDealer(this.value)" class="sel" >
        <option value="0">Select City</option>
        <? while($row=mysql_fetch_array($result)) {  ?>
        <option value><?=$row['FOR_DESC']?></option>
        <?} ?>
    </select>

DDL 的负载,但这些值未发布到数据库。形式

<div class="container">
<table width="528" border="0" cellpadding=1 class="formTable" style="width: 515px;font-family:arial;font-size:12px;" >
<form action="form_submit.php" method="POST" name="alto800" id="alto800" onsubmit="return validate();">
    <tbody>
        <tr>
            <td width="52%">Name</td>
            <td width="48%" >Mobile/Phone No.</td>
        </tr>
        <tr>
            <td>
                <select name="title" id="mr" class="sel">
                <option value="mr">Mr.</option>
                <option value="mrs">Mrs.</option>
                </select>
                <input type="text" name="name" id="name" class="formName" />
            </td>
            <td>
                <input type="text" name="mobile" id="mobile"/>
            </td>
        </tr>
        <tr>
            <td >State</td>
            <td >City</td>
        </tr>
        <tr>
            <td>
                <select name="state" id="state" class="sel"  onchange="getCity(this.value)">
                <option value="0">Select state</option>
                <option value="AN">ANDAMAN</option>
<option value="AP">ANDHRA PRADESH</option>
<option value="AR">ARUNANCHAL PRADESH</option>
<option value="AS">ASSAM</option>
<option value="BH">BIHAR</option>
<option value="CG">CHATTISGARH</option>
<option value="CH">CHANDIGARH</option>
<option value="DL">DELHI</option>
<option value="DM">DAMAN</option>
<option value="DN">DADRA & NAGAR HAVELI</option>
<option value="GJ">GUJRAT</option>
<option value="GO">GOA</option>
<option value="HN">HARYANA</option>
<option value="HP">HIMACHAL PRADESH</option>
<option value="JH">JHARKHAND</option>
<option value="JK">JAMMU & KASHMIR</option>
<option value="KL">KERALA</option>
<option value="KT">KARNATAKA</option>
<option value="MH">MAHARASHTRA</option>
<option value="ML">MEGHALAYA</option>
<option value="MN">MANIPUR</option>
<option value="MP">MADHYA PRADESH</option>
<option value="MZ">MIZORAM</option>
<option value="NG">NAGALAND</option>
<option value="OS">ORISSA</option>
<option value="PJ">PUNJAB</option>
<option value="PY">PONDICHERRY</option>
<option value="RJ">RAJASTHAN</option>
<option value="SK">SIKKIM</option>
<option value="TN">TAMIL NADU</option>
<option value="TR">TRIPURA</option>
<option value="UP">UTTAR PRADESH</option>
<option value="UT">UTTARANCHAL</option>
<option value="WB">WEST BENGAL</option>

                </select>
            </td>
            <td><div id="citydiv">
                <select name="city" id="city" class="sel" onChange="getDealer(this.value)" >
                <option value="0">Select state first</option>
                </select>
                </div>

            </td>
        </tr>
        <tr>
            <td >Preffered Dealer</td>
            <td >&nbsp;</td>
        </tr>
        <tr> 
            <td colspan="2"><div id="dealerdiv"><select name="dealer"  style="width:500px;height:25px;" >
              <option value="0">Select city first</option>
            </select>                   </div>  </td>
        </tr>
        <tr>
          <td>Email Address</td>
          <td>&nbsp;</td>
      </tr>
        <tr>
          <td><input type="text" name="email" id="email" /></td>
          <td>&nbsp;</td>
      </tr>
        <tr>
            <td >Your Query</td>
            <td rowspan="2" ><br />
              <br />            </td>
        </tr>
        <tr>
            <td>
             <textarea name="query" id="query"></textarea>

            </td>
        </tr>
        <tr>
            <td >
                <div style="height:10px"></div>
                <input type="image" name="submit" value="submit" src="images/submit.png" />
            </td>
            <td ></td>
        </tr>

    </tbody>
    </form>
</table>
4

0 回答 0