以下は私のコードです.私の仕事は、都市に基づいて、場所の変更です.したがって、都市を選択すると、1つのAjaxリクエストが送信され、場所がリセットされます.この場所は複数の選択ボックスであるため、複数の場所を選択できます.これに基づいて、ブランチを表示するには
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>