已经帮你修改到可以获取到值了..剩下的就自己做把..数据库名改回你自己的数据库名..
文件内容如下:
index.php<?php
if($_GET['act']=='insert')
{
echo "one-value:".$_POST['province_one']."<br>";
echo "two-value:".$_POST['province_two']."<br>";
echo "three-value".$_POST['province_three']."<br>";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var xmlHttp;
var requestType="";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function queryCity(citycode){
createXMLHttpRequest();
type="city";
var url="data.php?provincecode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}function queryArea(citycode){
createXMLHttpRequest();
type="area";
var url="data.php?citycode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}function handleStateChange(){
if(xmlHttp.readystate==4){
if(xmlHttp.status==200){
if(type=="city"){
showcity();
}else if(type="area"){
showarea();
}
}
}
}function showcity(){
document.getElementById("city").innerHTML=xmlHttp.responseText;
document.getElementById("area").innerHTML="";
}
function showarea(){
document.getElementById("area").innerHTML=xmlHttp.responseText;
}
</script>
</head>
<body>
<?php
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from province";
$result=mysql_query($sql);
echo "<form name='form1' action='?act=insert' method='post'>\n";
echo "<select id='province' name='province_one' onchange='queryCity(this.options[this.selectedIndex].value)'>\n";
echo "<option value='-1' selected>请?择省份</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
echo "<span id='city'></span>\n";
echo "<span id='area'></span>\n";
echo "<input type='submit'>";
echo "</form>\n";
?>
</body>
</html>
Data.php<?
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
if($provincecode!=""&&$provincecode!=650000&&$provincecode!=710000&&$provincecode!=810000&&$provincecode!=820000&&$provincecode!=110000&&$provincecode!=120000&&$provincecode!=310000&&$provincecode!=500000){
$sql="select * from city where provincecode=$provincecode";
$result=mysql_query($sql);
echo "<select onchange='queryArea(this.options[this.selectedIndex].value)' name='province_two'>\n";
echo "<option value='-1' selected>ffsdfsf</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
}
if($citycode!=""){
$sql="select * from area where citycode=$citycode";
$result=mysql_query($sql);
echo "<select name='province_three'>\n";
echo "<option value='-1' selected>fsdfsfs</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
}
?>
文件内容如下:
index.php<?php
if($_GET['act']=='insert')
{
echo "one-value:".$_POST['province_one']."<br>";
echo "two-value:".$_POST['province_two']."<br>";
echo "three-value".$_POST['province_three']."<br>";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var xmlHttp;
var requestType="";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function queryCity(citycode){
createXMLHttpRequest();
type="city";
var url="data.php?provincecode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}function queryArea(citycode){
createXMLHttpRequest();
type="area";
var url="data.php?citycode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}function handleStateChange(){
if(xmlHttp.readystate==4){
if(xmlHttp.status==200){
if(type=="city"){
showcity();
}else if(type="area"){
showarea();
}
}
}
}function showcity(){
document.getElementById("city").innerHTML=xmlHttp.responseText;
document.getElementById("area").innerHTML="";
}
function showarea(){
document.getElementById("area").innerHTML=xmlHttp.responseText;
}
</script>
</head>
<body>
<?php
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from province";
$result=mysql_query($sql);
echo "<form name='form1' action='?act=insert' method='post'>\n";
echo "<select id='province' name='province_one' onchange='queryCity(this.options[this.selectedIndex].value)'>\n";
echo "<option value='-1' selected>请?择省份</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
echo "<span id='city'></span>\n";
echo "<span id='area'></span>\n";
echo "<input type='submit'>";
echo "</form>\n";
?>
</body>
</html>
Data.php<?
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
if($provincecode!=""&&$provincecode!=650000&&$provincecode!=710000&&$provincecode!=810000&&$provincecode!=820000&&$provincecode!=110000&&$provincecode!=120000&&$provincecode!=310000&&$provincecode!=500000){
$sql="select * from city where provincecode=$provincecode";
$result=mysql_query($sql);
echo "<select onchange='queryArea(this.options[this.selectedIndex].value)' name='province_two'>\n";
echo "<option value='-1' selected>ffsdfsf</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
}
if($citycode!=""){
$sql="select * from area where citycode=$citycode";
$result=mysql_query($sql);
echo "<select name='province_three'>\n";
echo "<option value='-1' selected>fsdfsfs</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
}
?>
不好意思````,让你理解错了```我的意思是````比如现在选择的是:福建省-福州-长乐
将数据存入数据库里面了是没问题的```
如果要改变现在已选的值,
就要获取显示原来已选的:福建省-福州-长乐
再进行更改
但我无法将已选值,附值到菜单中,
麻烦 dada20042030 再帮帮忙```谢谢
index.php<?php
if($_GET['act']=='insert')
{
echo "one-value:".$_POST['province']."<br>";
echo "two-value:".$_POST['city']."<br>";
echo "three-value".$_POST['area']."<br>";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var xmlHttp;
var requestType="";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function queryCity(citycode){
createXMLHttpRequest();
type="city";
var url="data.php?provincecode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}function queryArea(citycode){
createXMLHttpRequest();
type="area";
var url="data.php?citycode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}function handleStateChange(){
if(xmlHttp.readystate==4){
if(xmlHttp.status==200){
if(type=="city"){
showcity();
}else if(type="area"){
showarea();
}
}
}
}function showcity(){
var return_value=xmlHttp.responseText.split('|');
document.getElementById("city").length=0;
for(var i=0;i<return_value.length;i++)
{
new_option=return_value[i].split(',');
option_text=new_option[0];
option_value=new_option[1];
document.getElementById("city").options.add(new Option(option_value,option_text));
}
}
function showarea(){
document.getElementById("area").length=0;
var return_value=xmlHttp.responseText.split('|');
for(var i=0;i<return_value.length;i++)
{
new_option=return_value[i].split(',');
option_text=new_option[0];
option_value=new_option[1];
document.getElementById("area").options.add(new Option(option_value,option_text));
}
}
function get_value(action)
{
/*
获取到数据以后就用ajax去插入和更新。要不然表单提交以后就会刷新的了。
*/
var provinces=document.form1.province.value;
var citys=document.form1.city.value;
var areas=document.form1.area.value;
alert("进行的动作是:"+action);
alert("省ID:"+provinces);
alert("市ID:"+citys);
alert("区域ID:"+areas);
}
</script>
</head>
<body>
<?php
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from province";
$result=mysql_query($sql);
?>
<form action="?act=insert" method="POST" name="form1" onsubmit="set_value();">
<select onchange='queryCity(this.options[this.selectedIndex].value)' id='province' name="province">
<?php
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
?>
</select>
<select id="city" onchange='queryArea(this.options[this.selectedIndex].value)' name="city"></select>
<select id="area" name="area"></select>
<input type="button" onclick="get_value('insert')" value="insert">
<input type="button" onclick="get_value('update')" value="update">
</form>
</body>
</html>data.php<?
$conn=mysql_connect("localhost","root","2260375");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
if($provincecode!=""&&$provincecode!=650000&&$provincecode!=710000&&$provincecode!=810000&&$provincecode!=820000&&$provincecode!=110000&&$provincecode!=120000&&$provincecode!=310000&&$provincecode!=500000){
$sql="select * from city where provincecode=$provincecode";
$result=mysql_query($sql);
while($row=mysql_fetch_row($result)){
$str.=$row[1].",".$row[2]."|";
}
echo $str;
}
if($citycode!=""){
$sql="select * from area where citycode=$citycode";
$result=mysql_query($sql);
while($row=mysql_fetch_row($result)){
$str.=$row[1].",".$row[2]."|";
}
echo $str;
}
?>
http://topic.csdn.net/u/20080319/10/1163a757-f29c-4555-8def-1acd120c7eb4.html
这个帖子也是我发的``
上次你有帮我改过一次``,但不是我想要的那种结果.
麻烦你再帮帮忙```谢谢```
<?php
//根据id取得相关变量
/*$id=$_GET['id'];
$conn=mysql_connect("localhost","root","passport");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from table where id='$id'";
mysql_connect($sql,$conn);
while($row=mysql_fetch_row($result)){
$dprovince=$row['provincecode']; //山西省
$dcity=$row['citycode']; //大同市
$darea=$row['areacode'];
}*///娴嬭瘯鍙橀噺涓?缁勮褰曟樉绀?$dprovince="140000"; //山西省
$dcity='140200'; //大同市
$darea='140227'; //大同县
//if($id)
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var xmlHttp;
var requestType="";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function queryCity(citycode){
createXMLHttpRequest();
type="city";
var url="data.php?provincecode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}function queryArea(citycode){
createXMLHttpRequest();
type="area";
var url="data.php?citycode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}function handleStateChange(){
if(xmlHttp.readystate==4){
if(xmlHttp.status==200){
if(type=="city"){
showcity();
}else if(type="area"){
showarea();
}
}
}
}function showcity(){
document.getElementById("city").innerHTML=xmlHttp.responseText;
document.getElementById("area").innerHTML="";
}
function showarea(){
document.getElementById("area").innerHTML=xmlHttp.responseText;
}
</script>
</head>
<body>
<?PHP
$conn=mysql_connect("localhost","root","passport");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from province";
$result=mysql_query($sql);
echo "<from id='form1'>";echo "<select id='province' onchange='queryCity(this.options[this.selectedIndex].value)'>";
//濡傛灉鎻愬彇鍑烘潵鐨勭渷鍊煎瓨鍦?
if($dprovince){
echo "<option value='-1' >璇烽?夋嫨鐪佷唤</option>";
}else{
echo "<option value='-1' selected>璇烽?夋嫨鐪佷唤</option>";
}while($row=mysql_fetch_row($result)){
if($row[1]==$dprovince){
echo "<option value='$row[1]' selected>$row[2]</option>";
}else{
echo "<option value='$row[1]'>$row[2]</option>";
}
}echo "</select>";echo '</span>';
//鍩庡競浠g爜
echo "<span id='city'>";
echo "<select onchange='queryArea(this.options[this.selectedIndex].value)'>";
if($dprovince){
$sql="select * from city where provincecode=$dprovince";
$result=mysql_query($sql,$conn);
if($dcity){
echo "<option value='-1' >璇烽?夋嫨鍩庡競</option>"; }else{
echo "<option value='-1' selected>璇烽?夋嫨鍩庡競</option>";
} while($row=mysql_fetch_row($result)){
if($row[1]==$dcity){
echo "<option value='$row[1]' selected>$row[2]</option>";
}else{
echo "<option value='$row[1]'>$row[2]</option>";
}
}
}
echo "</select>";echo '</span>';
//鏄剧ず鍦板尯echo "<span id='area'>";if($dprovince && $dcity){
$sql="select * from area where citycode=$dcity";
$result=mysql_query($sql,$conn);
echo "<select>";
if($darea){
echo "<option value='-1' >璇烽?夋嫨鍘垮尯</option>";
}else{
echo "<option value='-1' selected>璇烽?夋嫨鍘垮尯</option>";
} while($row=mysql_fetch_row($result)){
if($row[1]==$darea){
echo "<option value='$row[1]' selected>$row[2]</option>";
}else{
echo "<option value='$row[1]'>$row[2]</option>";
}
}
}
echo '</span>';echo "</form>";?>
</body>
</html>
但获取到之后,失去了联动菜单的功能,
又无法像原来那样选择别的城市进行修改,
麻再帮帮忙```
能不能在获取到原来已选的值的同时,
还能像原为那样还有联动菜单的功能,
选择别的城市进行修改