Chinaunix首页 | 论坛 | 博客
  • 博客访问: 44562
  • 博文数量: 5
  • 博客积分: 1723
  • 博客等级: 上尉
  • 技术积分: 40
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-19 14:11
文章分类

全部博文(5)

文章存档

2012年(1)

2011年(1)

2009年(3)

分类:

2009-07-30 13:37:35

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
//var ab = new Array();
var xmlHttp;

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
    
function startRequest() {
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    document.getElementById('select2').options.length = 0;
    var url = document.form1.select1.value;
    var qurl = "getCities.php?countryCode="+url+"&time="+new Date().getTime();
    xmlHttp.open("GET", qurl, true);
    xmlHttp.send(null);
    //setTimeout("startRequest()",2000);
}
    
function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
        var obj = document.getElementById('select2');
            eval(xmlHttp.responseText);
            
        }
    }
}

</script>
</head>

<body>
<form name="form1" method="post" action="">
  <p>
    <select name="select1" id="select1" onChange="startRequest()">
      <option value="0">选择</option>
      <option value="no">1</option>
      <option value="dk">2</option>
      <option value="us">3</option>
    </select>
</p>
  <p>
    <select name="select2" id="select2">
    </select>
</p>
</form>
</body>
</html>

<?php

if(isset($_GET['countryCode'])){
  
  switch($_GET['countryCode']){
    
    case "no":
      echo "obj.options[obj.options.length] = new Option('Bergen','1');\n";
      echo "obj.options[obj.options.length] = new Option('Haugesund','2');\n";
      echo "obj.options[obj.options.length] = new Option('Oslo','3');\n";
      echo "obj.options[obj.options.length] = new Option('Stavanger','4');\n";
      
      break;
    case "dk":
      
      echo "obj.options[obj.options.length] = new Option('Aalborg','11');\n";
      echo "obj.options[obj.options.length] = new Option('Copenhagen','12');\n";
      echo "obj.options[obj.options.length] = new Option('Odense','13');\n";
      
      break;
    case "us":
      
      echo "obj.options[obj.options.length] = new Option('Atlanta','21');\n";
      echo "obj.options[obj.options.length] = new Option('Chicago','22');\n";
      echo "obj.options[obj.options.length] = new Option('Denver','23');\n";
      echo "obj.options[obj.options.length] = new Option('Los Angeles','24');\n";
      echo "obj.options[obj.options.length] = new Option('New York','25');\n";
      echo "obj.options[obj.options.length] = new Option('San Fransisco','26');\n";
      echo "obj.options[obj.options.length] = new Option('Seattle','27');\n";
      
      break;
  }
}
?>

阅读(5108) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~