0

以下是我的代码。我的工作是根据城市,位置变化。所以一旦我选择城市,一个 Ajax 请求将发送并且位置将重置。这个位置是多个选择框,所以我可以选择多个位置。基于这个我想要显示分支。这里我的问题是当我改变城市时,多个下拉菜单即将到来。当我打印 alert($('#cboLocation option:selected').val()) 时,它唯一的警报第一个值

PHP 代码

<?php
     $arrCity = array('Chennai' => 'Chennai',
                         'Delhi'  => 'Delhi',
                         'Noida'  => 'Noida');
       $act     =   formatstring($_POST['act']);        
      switch($act)  
            {
                case "getCommonLocation":
                    $dbConn       = setDbConn();
                    $strCityName  = $_POST['CityName'];             
                    $strSQL = "SELECT distinct locality 
                                 FROM mp_new_project 
                                WHERE city = '".$strCityName."' ORDER BY locality ASC";         



                    $stmt = $dbConn->prepare($strSQL);
                    $stmt->execute();
                   // $stmt->bind_result($LocationId, $Location);
                   $stmt->bind_result($Location);

                    while($stmt->fetch())
                     //$arrLocations[] = array($LocationId, $Location);;   
                       $arrLocations[] = array($Location);              

                     for($i=0;$i<count($arrLocations);$i++)
                      $strOptionsList .= "<option value='".$arrLocations[$i][0]."'>".$arrLocations[$i][0]."</option>";  

                    $stmt->close();
                    $dbConn->close();

                    print "<option value='all'>All</option>".$strOptionsList;
                    exit();
                break;

            }

    ?>

Javascript

 <script type="text/javascript" src="scripts/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="scripts/jquery-ui-1.8.13.custom.min.js"></script>
    <script type="text/javascript" src="scripts/ui.dropdownchecklist-1.4-min.js"></script>
    <script type="text/javascript">
     function chnageToUP()
        {
         //  var selLoc =  $('#cboLocation option:selected').text();
          alert($('#cboLocation option:selected').val());
          return false;
        }
        function getCommonLocationForCities()
        {
        url         = 'testing1.php';
        strCityName =  $('#cboCity').val();
        //chnageToUP();

        $.post(
            url,
            {
                "act"       : "getCommonLocation",
                "CityName"  : strCityName
            },
            function(responseText){ 
                $('#cboLocation').val("");
                $('#cboLocation').html(responseText);
                $("#cboLocation").dropdownchecklist({firstItemChecksAll: true, 
                                                     maxDropHeight: 100,
                                                     onComplete: function(selector)
                                                     {
                                                        chnageToUP();
                                                      }});  
                },
            "html"
        );      
       }
    </script>

HTML 代码

<table style="margin-left:50px;" cellpadding="3" cellspacing="1" border="0" >
<tr>
     <td><b>City</b></td>
     <td><select name="cboCity" id="cboCity" onchange="getCommonLocationForCities()">
               <option  value="">City</option>
                <?php 
                   foreach($arrCity as $item)
                   {
                      print  "<option value='".$item."'>".$item."</option>";
                   }
                  ?>
       </select></td>
</tr>
<tr>
      <td><b>Location</b></td>
      <td> 
        <select name="cboLocation" id="cboLocation" class="select_142" multiple="multiple">   
         <option value='location'>Location</option>         
        </select>
      </td>
</tr>  
</table>

以下是链接 http://vignesh.gvignesh.org/dropdown/

4

2 回答 2

1

用于map获取数组中的检查值....

尝试这个

 function chnageToUP()
 {
     var tempArray="";
     tempArray=$('#cboLocation :checked').map( function() { return this.value; });
     console.log(tempArray);
     return false;
 }
于 2013-02-20T09:30:06.427 回答
0

alert() 不是很好的调试方法,请console.log()改用。需要您拥有 Firebug 或 Google Chrome 才能查看内容。

于 2013-02-20T09:24:37.237 回答