Load a page according to jQuery's autocomplete plugin

Posted on 2009-02-14
Last Modified: 2012-05-06
This should be trivial.

See the snippet below, using jQuery's autocomplete plugin ( It gives me two input boxes, one in which I can search users by their last name, the other by their username. I type a few letters, get a few suggestions, press enter and the last name or username appears. Up to that part, the documentation was good enough.

Then the documentation begins to go in all directions and seems to forget to explain the obvious: once I've found the person, I probably want to see his profile page after selecting him/her. Since I've loaded PHP arrays, it's really just opening the profile page for user number X.

So my question is simple: suppose that I autocomplete to Jack Smith, and want to see his profile page by clicking the enter key, (i.e., opening, say, user_profiles.php?user_id=332), what do I have to add to the snippet?
<script type="text/javascript" src="jquery/jquery-1.3.1.min.js"></script>

<script type="text/javascript" src="jquery/jquery.bgiframe.min.js"></script>

<script type="text/javascript" src="jquery/jquery.autocomplete.pack.js"></script>

<script type="text/javascript">


$(document).ready(function() {



$(document).ready(function() {





<p>Find by last name: <input type="text" id="last_names" /></p>

<p>Find by username: <input type="text" id="usernames" /></p>

Open in new window

Question by:CPL593H
    1 Comment
    LVL 6

    Accepted Solution

    So, i understand that you return the user_id from your PHP. In that case you can do (or change according to your needs):

    $(document).ready(function() {
    	$("input").result(function(event, data, formatted) {
    		document.location.href = "user_profiles.php?user_id=" + data[0];

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now