选择组合框后的ajax加载复选框 - php

时间:2015-09-14 15:06:24

标签: javascript php jquery ajax

请帮帮我! 我有一个表格,在城市中注册的社区寻找ajax,选择这个城市,并选择加载的社区。 它工作得很好,但我需要放置复选框,这样你就可以选择多个社区,我尝试了,但它没有成功。 我试图使用jQuery插件MULTIPLE SELECT。

<head>
    <link href="multiple-select.css" rel="stylesheet"/>

<script language="javascript">
function search_data(city)
{
  ajax.open("GET", "search.php?city=" + city, true);
  ajax.onreadystatechange = handleHttpResponse;
  ajax.send(null);
}
function handleHttpResponse()
{
  campo_select = document.form_av.neighborhood;
  if (ajax.readyState == 4) {
    campo_select.options.length = 0;
    results = ajax.responseText.split(",");
    for( i = 0; i < results.length; i++ )
    {
      string = results[i].split( "|" );
      if ( string[0] != "" ){
      campo_select.options[i] = new Option( string[0], string[0] );
      } else {
      campo_select.options[i] = new Option( "all neighborhoods" , "", "defaultSelected","selected" );
      }
    }
  }
}
function getHTTPObject()
{
    if(window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    } else
    if(window.ActiveXObject)
    {
        var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"]; 
        for(var i = 0; i < prefixes.length; i++)
        {
             try
            {
             return new ActiveXObject(prefixes[i] + ".XMLHTTP");
            } catch (e) {}
        }
    }
}
var ajax = getHTTPObject();
</script>

</head>
<body>

<form name="form_av" id="hongkiat-form" method="get" action="">


                    City

                    <select name="city" size="1" class="txtinput" id="city" style="width:130px;" onChange="search_data( this.value )">
                        <option selected value="">Todas</option>
                        <? $consulta = mysql_query("SELECT * FROM city ORDER BY city_name ASC");
                        while( $row = mysql_fetch_assoc($consulta)){?>
                        <option value="<? echo retira_acentos($row['city_name']);?>"><? echo retira_acentos($row['city_name']);?></option>
                        <? }?>
                    </select>




                   Neighborhood

                    <select name="neighborhood" size="1" class="txtinput" id="neighborhood" style="width:130px;" multiple="multiple">
                        <option value="" selected>------</option>
                    </select>

               </form>

    <script src="jquery-1.7.2.min.js"></script>    
    <script src="jquery.multiple.select.js"></script>
    <script>
        $('#neighborhood').multipleSelect();
    </script>

</body>

谢谢!

1 个答案:

答案 0 :(得分:0)

I don't see where you need checkboxes to do that. However I think i know what is bugging on your code: You do a

$('#neighborhood').multipleSelect();

but when this line is executed, the city is not provided so the multipleselect will be empty. You have to execute the multipleSelect at the end of the search_data function.

hope this will help