auto filter and autocomplete
Hi ,
I need to filter per country first through dropdown select by country, then autosuggest/autocomplete on the input textbox the companies under the countries selected.
My question is : How do I pass the variable from dropdown?
Here are by codes below :
1st page (index)
- //dropdown
- <select name="f_country_id" class="form-control" id="f_country_id">
- <option value="?cid=0&code=0" >-- Select Country --</option>
- <?php
- while($country = $sql_getCountries->fetch_assoc()){
- echo '<option ';
- if($country['id'] == $_GET['cid']){
- echo ' selected ';
- }
- echo 'value="?cid='.$country['id']'.'">'.$country['d_name'].'</option>';
- }
- ?>
- </select>
- <input type='text' name='d_name' value='' class='auto form-control' id="d_name" placeholder="Name of Company/Establishment" >
- <!--- start here Autoload ////////// --->
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
- <script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>
- <script type="text/javascript">
- $(function() {
- //autocomplete
- $(".auto").autocomplete({
- source: "auto_search.php" ,
- //minLength: 1
- });
- });
- </script>
- <!--- End here Autoload Scripts ////////// --->
2nd page (auto_search.php)
- if (isset($_GET['term'])){
- $return_arr = array();
- try {
- $conn = new PDO("mysql:host=".DB_SERVER.";dbname=".DB_NAME, DB_USER, DB_PASSWORD);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $conn->prepare("SELECT a.* FROM tb_company_establishment a WHERE a.d_name LIKE :term");
- $stmt->execute(array('term' => '%'.$_GET['term'].'%'));
-
- while($row = $stmt->fetch()) {
- $return_arr[] = $row['d_name'];
- }
- } catch(PDOException $e) {
- echo 'ERROR: ' . $e->getMessage();
- }
- /* Toss back results as json encoded array. */
- echo json_encode($return_arr);
- }
If only i can pass from the dropdown country variable to auto_search page then it can solve the problem.
Hope you can help me, im not used to jquery or javascript.
Thanks in advance