Autocomplete

Discussion in 'Programming' started by haaheey, Aug 17, 2012.

  1. #1
    Hi,

    Is it possible to create an autocomplete program that can be used with word processing applications? I've seen some of these programs that were created using jQuery, PHP...etc. But they need a browser.
     
    haaheey, Aug 17, 2012 IP
  2. sh4rd

    sh4rd Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Bit confusing. Care to expand? If something can be made using PHP, you can pretty much assume it could be made as a desktop application
     
    sh4rd, Aug 19, 2012 IP
  3. GuiltyDragon

    GuiltyDragon Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You mean as a plugin for MSWord or OpenOffice or a standalone program that runs in your OS and inspects every piece of typed text? Doesn't sound like it would be beyond the realms of possibility but it's not the kind of thing I've attempted before. Also I agree with sh4rd. If it's been done in a web app then it'll be possible (easier perhaps) in a desktop app.
     
    GuiltyDragon, Aug 21, 2012 IP
  4. haaheey

    haaheey Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, thank you guys for taking the time to reply.

    In fact, I’ve attempted to create a php script that somewhat resembles what I would need. I actually followed one of the php tutorials available on Youtube. The code that I’ve done so far is as follows:


    HTML (index.php):

    <!DOCTYPE html>
    <html>
    <head>
    <title>Autosuggest field</title>
    <link rel="stylesheet" href="css/screen.css">
    </head>
    <body>

    <textarea rows="10" cols="10" class="autosuggest"></textarea><input type="submit" value="Search">
    <div class="dropdown">
    <ul class="result"></ul>

    <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    <script src="js/primary.js"></script>




    <?php


    ?>

    </body>


    </html>


    jQuery Script:


    $(document).ready(function(){
    $('.autosuggest').keyup(function(){

    var search_term = $(this).attr('value');
    $.post('ajax/search.php', {search_term:search_term}, function(data){
    $('.result').html(data);

    $('.result li').click(function(){
    var result_value = $(this).text();
    $('.autosuggest').attr('value', result_value);

    $('.result').html('');
    });
    });
    });
    });



    PHP Script:

    <?php
    require_once '../core/connect.php';

    if(isset($_POST['search_term']) == true && empty($_POST['search_term']) == false){

    $search_term = mysql_real_escape_string($_POST['search_term']);

    $query = mysql_query("SELECT `city` FROM `cities` WHERE `city` LIKE '$search_term%'");
    while(($row = mysql_fetch_assoc($query)) !== false){
    echo '<li>', $row['city'], '</li>';

    }

    }
    ?>


    Connecting to the Database:

    <?php

    mysql_connect('localhost', 'root', '');
    mysql_select_db('autosuggest');

    ?>


    The above code produces the following:


    Autosuggest.jpg

    The database contains a list of cities. Thus, when I click the letter "L" for example, I get three suggestions out of which I can choose one. But what I want is two things:

    1. After selecting one of the three suggestions and hitting the space-bar, I want to be able to proceed within the Text-area (by the way, I figured I could use a Text-area instead of using a word processing application.), and get another set of suggestions for whatever letter I put in. I can't seem to be able to do that right now, as I get no suggestions after selecting one result out of the previous three suggestions and hitting space-bar.

    2. Secondly, I would like to attach numbers to the suggestions in the following fashion:


    Autosuggest_0001.jpg

    The reason I want this feature is so that I can choose the desired suggestion simply by pressing the associated number with the suggested word/phrase without having to hover over it with the mouse and clicking it.

    I hope the above will give you an Idea of what I have in mind, and that you'll be able to help me.

    Thanks in advance.
     
    Last edited: Aug 30, 2012
    haaheey, Aug 30, 2012 IP
  5. haaheey

    haaheey Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    By the way, I know that there are already some software out there that could accomplish almost what I've described in my previous post. But I want to do this with another language, not in English. Most of these software support at best a handful of major languages.
     
    haaheey, Aug 30, 2012 IP