Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Location
    San Francisco
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New guy with a question about the jQuery Autocomplete feature

    I am using this on a website that I am building.
    http://jqueryui.com/demos/autocomplete/default.html

    If I type in "Co" in the field in the URL above, it shows a few suggestions, but I want to take the user to a URL or another HTML page when they click on one of the suggestions.

    How do you link the values to another page?

    Thanks
    Raj

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,957
    Thanks
    9
    Thanked 727 Times in 721 Posts
    If you're just holding the possible lookups locally, as opposed to a database, then something like:

    Code:
    $(function() {
    var webSites = [{value:"Google",url:"http://www.google.com"},{value:"Coding Forums",url:"http://codingforums.com"}];
     
    //autocomplete
    $("#lookup").autocomplete({
        source: webSites,//look up the variable already created
        minLength: 2,//search after two characters,
        select: function(event,ui){
    		window.location.href =  ui.item.url;//on select, navigate to the url selected
    		}
        });
    	
    });
    ought to do the job. UI Autocomplete shows the field 'value' in the dropdown, here we're also retrieving a field 'url', which we then use to load a new page on select.

    If you're holding the data in a database then it's pretty much the same principle, but obviously you'd need to connect to and retrieve from the database.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •