我现在的做法:
表单下拉框中有10个项(从数据库中读出),点击每一项的时候,都刷新一下这个页面,然后取到这个项的值。例如:选择了一项,刷新页面,页面变为:http://www.abc.com/xiang.php?num=5 ,然后取到这个值5,,再用php进行判断,<? if $_GET[num]==5 {执行一段程序,把值为5的分类全部取出};?>
我感觉这种做法太麻烦了,我想这样:从下拉框中选出一项,然后通过ajax,把这项的值取到,然后用这个值取出分类就是不刷新页面,就到到上面的目的,大家帮我看看能不能实现,应该怎么实现?

解决方案 »

  1.   

    可以实现的啊,就是我不太清楚ajax怎么样和php交互的;
      

  2.   

    JavaScript里
    var ddlist  = document.getElementById("DropDownList1");
    ddlist.options[ddlist .selectedIndex].text; //取得text值
    ddlist.options[ddlist .selectedIndex].value; //取得value值
      

  3.   

    Ajax将select的value传递给PHP,PHP选取结果后以JSON的格式将数据返回,JS解析responseText并更新select
      

  4.   

    got it, it can be done like this.// javascriptvar xml_get_list;//here do the job
    var get_list=function(){    //initialize the xmlhttprequest object
        if(window.XMLHttpRequest){
            xml_get_list=new XMLHttpRequest();
        }else if(typeof ActiveXObject != "undefined"){
            xml_get_list=new ActiveXObject("Microsoft.XMLHTTP");
        }    var list_code=document.getElementById("listName").value;    xml_get_list.open("GET","get_list.php?list_code="+list_code,true);    //define the deal response method
        xml_get_list.onreadystatechange=_list_state_change;    xml_get_list.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    xml_get_list.send(null);
    }//here deal the responsevar _list_state_change=function(){
        if(xml_get_list.readyState==4){         //I think you should know how to deal with it all right?
             alert(xml_get_list.responseText);    }
    }
      

  5.   

    you can add an event, onchange do that get_listand then add a file named get_list.php to get the code the function sent$_GET['list_code'], then output a select list you want which depend on the list_code
      

  6.   

    just like this.<select>
    <?php
    is_int($_GET['list_code']) or die(error());switch($_GET['list_code']){
    //echo different data with different cases
    }?>
    </select>
      

  7.   

    ajax可以实现,这和论坛注册时候判断用户名是否存在很相似,只不过这里是下拉菜单(onchange事件判断)。
    逻辑:
    下拉菜单,onchange事件调用ajax代码,并将当前值传递给ajax,ajax根据传递过来的值,进行处理并最终得到一些信息,显示中页面中某个标签处(个人喜欢span标签)
      

  8.   

    回复人:njaufire() ( 一级(初级)) 信誉:100  2007-6-11 18:30:25  得分:0
    ?  中文很牛B的老外?
    ==================================
    gjm
      

  9.   


    回复人:hy_lihuan(我想早恋,可是已经晚了) ( 三级(初级)) 信誉:100  2007-6-11 16:07:50  得分:0
    ?  可以实现的啊,就是我不太清楚ajax怎么样和php交互的;===========在它的onchange事件里写交互代码就行了。