表格:
<form id="regd" enctype="multipart/form-data" method="post" action="register_action.php">
<tr>
<td>Name</td>
<td><input type="text" size="26" name="txtname" required="required" /> </td></tr>
<tr>
<td>Em@il id</td>
<td><input type="email" size="26" name="txtemail" required="required" /> </td></tr>
<tr>
<td>Password</td>
<td><input type="password" size="26" name="pwd1" required="required"> </td></tr>
<tr> <td>Country</td>
<td><div><select required="true" name="country" id="country">
<option value="">Select Country</option>
<?php while ($row=mysql_fetch_array($result)) { ?>
<option value=<?php echo $row['country_id']?>"<?php echo $row['country_name']?>"><?php echo $row['country_name']?></option>
<?php } ?>
</select></div> </td></tr>
<tr>
<td>State/td>
<td>
<div id="statediv">
<input name="state" type="text" maxlength="255" value="" required="required" title="Select Country first"/>
</div>
</td></tr>
<tr>
<td><input id="btn_cancel" type="reset" value="Cancel" class="regdbutton"></td>
<td><input id="btn_submit" type="submit" /></td></tr>
</form>
这是表单,我想在其中输入值到数据库,并且它也是在没有那个状态的情况下进入,它已经通过Ajax加载了。下面是代码(我已经跳过了那个函数XmlHTTP的东西)因为这会使代码更长)
Ajax Part:
<script language="javascript" type="text/javascript">
function getState(countryid) {
var strURL="findState.php?country="+countryid;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
document.getElementById('statediv').innerHTML=req.responseText;
document.getElementById('citydiv').innerHTML='<select name="city">'+
'<option>Select City</option>'+
'</select>';
} else {
alert("Problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
寻找城市:
<?php $country=intval($_GET['country']);
include("config.php");
$query="SELECT state_id,state_name FROM state WHERE country_id='$country'";
$result=mysql_query($query);
?>
<select style="width:190px;" class="element select medium" name="state" onchange="getCity(<?php echo $country?>,this.value)" title="State">
<option>Select State</option>
<?php while ($row=mysql_fetch_array($result)) { ?>
<option value=<?php echo $row['state_id']?>"<?php echo $row['state_name']?>"><?php echo $row['state_name']?></option>
<?php } ?>
</select>
我没有发布我的操作代码,因为它运行正常,错误“未定义的索引状态”并且值没有输入。