我已经为我的网站实现了自动完成搜索栏。我将在index.php页面中选择位置。从index.php页面选择的位置也必须反映到mydealers.php页面。但它没有发生。而是显示其他位置名称。
HTML代码
<div style=margin-left:500px;margin-top:-40px;width:500px>
<?php
echo " <select data-live-search='true' data-live-search-style='startsWith' class='selectpicker' id='locName'>";
$stmt = $conn->prepare('SELECT LocationName From arealistmain');
$stmt->execute();
while($row = $stmt->fetch()) {
echo " <option>" .$row['LocationName'] . "</option>";
}
echo "</select>";
?>
</div>
Java Script
<!--AutoComplete Search bar-->
$(function() {
$("#locName").autocomplete({
minLength: 1,
function(event) {
var value = event.getAttribute('value')
var locName = document.getElementById("locName").value;
if (value.includes('&')) {
value = value.replace("&", "%26");
}
if (locName == "") {
alert("Please Select your Location");
} else {
window.location = "http://www.citycontact.in/MyDealers.php?id="+value+"&locName="+locName;
}
return false;
}
});
});
<!--Auto Complete For Categories-->
function Demo(anchor) {
var value = anchor.getAttribute('value')
var locName=document.getElementById("locName").value;
if(value.includes('&')){
value = value.replace("&", "%26");
}
if(locName==""){
alert("Please Select your Location");
} else {
window.location = "http://www.citycontact.in/MyDealers.php?id="+value+"&locName="+locName;
}
}