javascript - Combine input box and select box to create a search bar -
i have input box serves search box, , populate select box querying sql database. example, there 2 organizations called "dummy organization" , "dummy 2" in db. when user starts typing "du", select box fills 2 organizations. want combine these 2 fields: input box (that acts search box) , select box (which displays results). research shows selectize.js can useful, since i'm new js, can't figure out how. can please me? code below:
js gets data db:
<script type="text/javascript"> function searchq(){ var searchtxt = $("input[name='search']").val(); $.post("search.php", {searchval: searchtxt},function(output4){ $("#output4").html(output4); } </script>
the form:
<form action="newbrand.php" method="post" id="form"> <br> brand name: <input type="text" name="bname" required /><br><br> search organization: <input type="text" required name="search" onkeyup="searchq()" id="output"><br><br> selected organization: <select id="output4" name="taskoption"></select> </form>
the search.php file
<?php include 'db_connect.php'; $link = mysqli_connect($host, $username, $password, $db); if(!link){ echo "db connection error"; } $output = '' ; $output2 = '' ; if (isset($_post['searchval'])){ $searchq = $_post['searchval']; //$searchq = preg_replace("#[^0-9a-z]#i","",$searchq); $query = mysqli_query($link, "select * `organisations_info` `organisation_name` '%".$searchq."%' ")or die("could not search!"); $count = mysqli_num_rows($query); if($count == 0){ $output = '<option>no results!</option>'; }else{ while($row = mysqli_fetch_array($query)){ $orgname = $row['organisation_name']; $orgid = $row['organisation_id']; $subs = $row['subscription_type']; ?> <option value="<?php echo $orgid; ?>"><?php echo $orgname; ?></option> <div><?php echo $subs; ?></div> <?php } // while } // else } // main if ?>
Comments
Post a Comment