Code: Select all
<script>
function precheck(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","ajax-search.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<?php echo "<div class='home-search'>
<div class='home-search-inner'>
<form method='GET' action='/index.php'>
<input type='hidden' name='page' value='search'>
<div class='home-search-icon'><i class='fa fa-search' aria-hidden='true'></i></div>
<div class='home-search-input'> <input type='text' name='search' placeholder='Search the site'";
if (isset($search)) { echo " value='";
?><?= htmlspecialchars($search); ?><?php
echo "'";}
echo " onChange=\"precheck(this.value)\"></div>
<div class='home-search-cat'><select name='category'>
<option value='all'>All Categories</option>";
$query = "SELECT DISTINCT catname FROM products WHERE pause <> 'on' ORDER BY catname";
$result = $pdo->query($query);
while ($row = $result->fetch(PDO::FETCH_OBJ))
{
echo "<option value='$row->catname'";
if (isset($categorysearch))
{
if ($row->catname == $categorysearch) { echo " selected='selected'";}
}
echo ">$row->catname</option>";
}
echo "</select></div>
<div class='home-search-submit'><input type='submit' value='search'></div>
</form>
<div style='clear: both'></div>
</div></div>
<div id='txtHint'><b>Person info will be listed here...</b></div>";But how do I make it pass the dropdown menu <select> option in the Ajax query as well?
Ideally, if they typed in something, and it came up with the answers, and then they switched the dropdown <Select> to a different category, the options would change.
Trouble is, there is one or two main keywords here that means hundreds of products can be found.
Tho I can limit it I suppose.