Home Answers Viewqa Ajax AJAX Search

 
 


Saakshi Dikshit
AJAX Search
3 Answer(s)      8 months ago
Posted in : Ajax

I have to create a project where the user enters a letter in a text box and all the names starting with that letter are retrieved. I'm using PHP and MYSQL as the database. Can somebody please suggest me the AJAX coding of this.

View Answers

October 4, 2012 at 5:11 PM


Here is a php code that shows autosuggest box.

1)index.php:

<html>
<head>
<script type="text/javascript" src="./plugin/jquery.js"></script>
<script>
function suggest(inputString){
        if(inputString.length == 0) {
            $('#suggestions').fadeOut();
        } else {
        $('#country').addClass('load');
            $.post("autosuggest.php", {queryString: ""+inputString+""}, function(data){
                if(data.length >0) {
                    $('#suggestions').fadeIn();
                    $('#suggestionsList').html(data);
                    $('#country').removeClass('load');
                }
            });
        }
    }

    function fill(thisValue) {
        $('#country').val(thisValue);
        setTimeout("$('#suggestions').fadeOut();", 600);
    }

</script>

<style>
#result {
    height:20px;
    font-size:16px;
    font-family:Arial, Helvetica, sans-serif;
    color:#333;
    padding:5px;
    margin-bottom:10px;
    background-color:#FFFF99;
}
#country{
    padding:3px;
    border:1px #CCC solid;
    font-size:17px;
}
.suggestionsBox {
    position: absolute;
    left: 0px;
    top:40px;
    margin: 26px 0px 0px 0px;
    width: 200px;
    padding:0px;
    background-color: #000;
    border-top: 3px solid #000;
    color: #fff;
}
.suggestionList {
    margin: 0px;
    padding: 0px;
}
.suggestionList ul li {
    list-style:none;
    margin: 0px;
    padding: 6px;
    border-bottom:1px dotted #666;
    cursor: pointer;
}
.suggestionList ul li:hover {
    background-color: #FC3;
    color:#000;
}
ul {
    font-family:Arial, Helvetica, sans-serif;
    font-size:11px;
    color:#FFF;
    padding:0;
    margin:0;
}

.load{
background-position:right;
background-repeat:no-repeat;
}

#suggest {
    position:relative;
}

</style>
</head>

<body>




 <form id="form" action="#">
    <div id="suggest">Start to type a country: <br />
      <input type="text" size="25" value="" id="country" onkeyup="suggest(this.value);" onblur="fill();" class="" />

      <div class="suggestionsBox" id="suggestions" style="display: none;"> 
        <div class="suggestionList" id="suggestionsList"> &nbsp; </div>
      </div>
   </div>
</form>



</body>
</html>

Please visit the following link:

http://www.roseindia.net/tutorial/ajax/jquery/autocomplete.html


October 4, 2012 at 5:12 PM


continue..

<?php
   $db_host = 'Your database host name';
   $db_username = 'Your datbase username';
   $db_password = 'Your database password';
   $db_name = 'Your database name';

   $db = new mysqli($db_host, $db_username ,$db_password, $db_name);

    if(!$db) {

        echo 'Could not connect to the database.';
    } else {

        if(isset($_POST['queryString'])) {
            $queryString = $db->real_escape_string($_POST['queryString']);

            if(strlen($queryString) >0) {

                $query = $db->query("SELECT country FROM countries WHERE country LIKE '$queryString%' LIMIT 10");
                if($query) {
                echo '<ul>';
                    while ($result = $query ->fetch_object()) {
                        echo '<li onClick="fill(\''.addslashes($result->country).'\');">'.$result->country.'</li>';
                    }
                echo '</ul>';

                } else {
                    echo 'OOPS we had a problem :(';
                }
            } else {
                // do nothing
            }
        } else {
            echo 'There should be no direct access to this script!';
        }
    }
?>

For more information, visit the following link:

Please visit the following link:

http://www.roseindia.net/tutorial/ajax/jquery/autocomplete.html


October 4, 2012 at 5:12 PM


The above code is autosuggest.php.









Related Pages:
AJAX Search
AJAX Search  I have to create a project where the user enters... using PHP and MYSQL as the database. Can somebody please suggest me the AJAX...://www.roseindia.net/tutorial/ajax/jquery/autocomplete.html   continue
Auto Search box using ajax
Auto Search box using ajax   Hi , i want to implement auto search box functionality like google and linkedin using ajax,jsp,servlet, javascript etc.when the value appears on the textbox then we should also be able to select
How to perform search using AJAX?
How to perform search using AJAX?  Hi, I have following HTML code... and hit button, there is a Ajax call to retrieve search results from a simple txt...; <td><label for="status">Search Status</td> <td><input
ajax
ajax  HI, In my application using ajax if i type a managername... on search button it should display the employee details from database pls help me reg this. thanks KK   Combobox box using Ajax in JSP   i
Auto complete of word search using ajax with java
Auto complete of word search using ajax with java  I want to display... using jsp to design the form. I want ajax sample to achieve this feature. Its like google search. Please help. Thanks in advance
Auto complete of word search using ajax with java
Auto complete of word search using ajax with java  I want to display... using jsp to design the form. I want ajax sample to achieve this feature. Its like google search. Please help. Thanks in advance
ajax with php - Ajax
ajax with php  how to do autocomplete search using ajax wit php in object oriented format?.. data should me retrive from database.. plz the way?.. give some sample codings
Ajax in struts application - Ajax
Ajax in struts application  I have a running application using struts and now i want to implement Ajax(for populating some search box) in it.The problem is that my jsp page is able to send the request to my Struts Action process
JSF Search Application Using Ajax
JSF Search Application Using Ajax      Here, Roseindia Tutorial Section provides you a JSF search application using Ajax. This is a simple application in which, you will see two JSF
search
search  how to develop search box and how to retrive data from database..   Please visit the following link: Search box
SEARCH
SEARCH  how can we do search in jsp...? option for search criteria like name and DOB...   Please visit the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
Autocompleteextender - Ajax
Search .normal { background-color: #FFFFFF; padding: 2px 6px 2px 6px; } .over... searchText() { var search = document.getElementById("search").value; var url = "/jsp/AutocompleterTest?search=" + search; if(window.XMLHttpRequest){ xmlHttp = new
Google Ajax API
Google Ajax API  Hi, What is Google Ajax API? From where I can get in our application. Thanks   Hi, Google AJAX APIs is a JavaScript..., search, or feed-based Internet content into web applications/pages, organized
Ajaxium ajax for asp.net
Ajaxium ajax for asp.net       Ajaxium ajax for asp.net is the universal AJAX container for all ASP.NET pages and controls. In contrast to other AJAX-based approaches and huge AJAX
ajax+dropdown+table format
ajax+dropdown+table format  HI, i am looking for an ajax application which must contain two dropdown list.In first dropdown if i select a manager... come and then if i select the one reportee,upon click on a search button
ajax
ajax  please describe the ajax
Ajax
Ajax  How to learn AJAX
Ajax Technology
Ajax Technology         Ajax Technology Asynchronous JavaScript and XML or Ajax for short is a type of asynchronous programming technical to develop
Ajax
Ajax  Hi, What is Ajax? What is the use of Ajax? Thanks   Hi, Ajax is set of technologies used to develop dynamic web applications. In Ajax following technologies is used: a) JavaScript b) XML c) HTTP d) CSS Learn
Ajax Books
Ajax Books       AJAX... and resources will help you stay on top of AJAX happenings Up until now there have been few books on DHTML and only 2-3 that cover AJAX. But that will change
Java JSP - Ajax
search lists public void editSearchList(int searchID, String searchValue...() { } // insert new admin search list into db public void insertNewSearchList...){ System.out.println("Error : Empty Search List !"); }else
Ajax
Ajax  how to impliment ajax in registration table using jsp-servlet
Ajax
Ajax  send the example to fetch the data from the server by using ajax in java. for ex:-if there are states which is used to display in frontend we use ajax. send it to me
ajax+options is null or not an Object
ajax+options is null or not an Object  HI i have developed a simple ajax application contains two drop down lists and and one search button when i... the employee names on selection of the employee name and i kept search it should
Ajax
Ajax  how to include ajax in jsp page?   Hi, Please read Ajax First Example - Print Date and Time example. Instead of using PHP you can write your code in JSP. Thanks
ajax
ajax  how to connect ajax with mysql without using php,asp or any other scripting language. please answer soon
Ajax - Ajax
Ajax  What is Ajax ? How one can use ajax with Java
Open Source Ajax
Ajax Conversion Ajax Search...Open Source Ajax Source Ajax frameworks for developing cutting edge web 2.0 applications to satisfy your clients. There are many Open Source Ajax
enabling parts of a search button based on the ssn boxes filled.
enabling parts of a search button based on the ssn boxes filled.  I want to do an AJAX program to search a particular ssn. Currently I have ssn field with 3 text boxes and a search button to search the particular ssn. I want
Ajax Examples
Ajax Examples       There are a few AJAX demos and examples on the web right now. While these are invaluable to learning AJAX, some people need a bit more information than just
Ajax
in a tabular form. Same for >33kv We can use ajax where instead of a link a radio button can fetch the data and can populate a table.If ajax can be used
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
To display suggestions in a text box - Ajax
. 1) Go to flazx.com, Search for Ajax Book 2) Download Book "Ajax on Java" 3... the Ajax : Some steps to be memeber : 1)Create a text box on the JSP Page. 2)On this text box call a function onKeyUp event using Ajax. 3)Pass the value
How can i search and insert within a query
How can i search and insert within a query  if it is possible... semester and degree if i search batch 2008 , semester first and degree bscs then search... event in ajax entermarks.php <html> <head> <meta http-equiv
Ajax
options. I want to do it using ajax. My table is CREATE TABLE HT<em>
AJAX
ajax. My table is CREATE TABLE HTNEWMETER ( ID NUMBER (10) NOT NULL, METERNO
ajax
ajax  I am facing following problem, I am using ajax to get the data continousely without refreshing. Here i have devided a web page into 3 parts(top,left and right) using table in jsp. On the left part i am displaying some