Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4054764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:37:01+00:00 2026-05-20T14:37:01+00:00

I want to do some autosuggest for my text field, using this plugin AutoSuggest

  • 0

I want to do some autosuggest for my text field, using this plugin AutoSuggest jQuery Plugin

I have an array, already json_encoded, and the files on the server, js, css, but Im not getting yet how the example works, here my code,

<html>
 <head>
  <title>test-data</title>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="inc/css/admin_style.css" rel="stylesheet" type="text/css">
     <link href="inc/css/autoSuggest.css" rel="stylesheet" type="text/css">
     <script language="javascript" src="inc/js/functions.js"></script>
     <script language="javascript" src="inc/js/jquery-1.5.1.js"></script>
     <script language="javascript" src="inc/js/jquery.autoSuggest.js"></script>
     <script language="javascript" type="text/javascript">
      </script>
 </head>

 <body>
 <center><br><font class="title">test</font></center>

  <form action="dataAll.php" method="post">
   Name: <input type="text" name="fname" />
  <input type="submit" />
   </form>

   <p>&nbsp;</p>
  <p>JSON</p>
  <p>&nbsp;</p>
  <?php
  $encoded =  json_encode ($familyNames);
  echo $encoded;
   ?>
  </body>
  </html>

so Im supposed to put this code,

 $(function(){
 $("input[type=text]").autoSuggest(data);
 });
  • but the question is where??( as if I put it inside the php tags, it gives me an error
  • where should I put the name of my json formatted array? “$encoded” for the function to recognize that is the source of data?

thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:37:01+00:00Added an answer on May 20, 2026 at 2:37 pm

    You’ve got all the pieces, but your order/methodology is a bit off. Try creating a second file, named something like ajax.php, and place all of your php code in there. To ensure you are outputting good JSON, add the line header('Content-Type: text/json; charset=ISO-8859-1'); at the very beginning of the ajax.php file (you must set the header before any output is sent or you’ll get an error). Now you’ve got to request your suggestion data:

    $(document).ready(function() {   // Runs when your page is loaded in the user's browser
        $.getJSON('ajax.php', function(data) { // Runs ajax.php, then executes an anonymous function to handle the response
            $('input[name="fname"]').autoSuggest(data); // Set your input field to use automatic suggestions with the returned data
        }); // end getJSON
    }); // end ready
    

    This code simply executes an asynchronous HTTP request for ajax.php, and hands off the returned JSON data to the auto-suggest jQuery plugin. Place it inside a <script type="text/javascript"></script> tag. It will run once when the page loads due to the use of $(document).ready(...). I added the small optimization (input[name="fname"]) so jQuery doesn’t attempt to attach the auto suggestion functionality to every text input you have on your page. If thats what you wanted to do (unlikely), just change it back to input[type=text].

    You really do not need a separate php file to get this to work. There is nothing stopping you from doing it all in one file, but you’ll soon realize how cluttered and unmanageable that can get. For me, its easiest to think of my “ajaxy” php code as a single, modular piece of my web application.

    Be sure to reference these pages for detailed information:

    • http://api.jquery.com/
    • http://api.jquery.com/ready/
    • http://api.jquery.com/jQuery.getJSON/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working to build a jQuery AutoSuggest plugin, inspired by Apple's spotlight. Here is
I want some slightly 'dynamic' XML source files. I want some of the element
I want some particular urls like springer.com to automatically convert to springer.com.proxy1.mycollege.edu. The second
I want some of the items to be bold depending on a property of
I want some personally developed JavaScript code to execute whenever I load a page
I want some tags to be added to an article. The problem is that
I want some application to look like widget inside my Python application. That's all.
I want some variables to be global across the project and accessible in every
I want some examples of C preprocessor directives, such as: #define pi 3.14 #define
I want some code to be triggered every second. Usually, I'd create a Timer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.