We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Load a page according to jQuery's autocomplete plugin

CPL593H asked
Medium Priority
Last Modified: 2012-05-06
This should be trivial.

See the snippet below, using jQuery's autocomplete plugin (http://docs.jquery.com/Plugins/Autocomplete). 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

Watch Question

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.