Jquery autocomplete links -


i use jquery's autocomplete on site. right menu produces has links can click.

however, when click them go text field. able click on link (or press enter) , taken page, change url's variable.

to make little more complicated, each item in drop down assigned id mysql database. link each item should go index.php?id=$id $id id database.

since have hundreds of items in menu, how can alter current code include links redirect index.php?id=$id getting $id database?

code: standard code http://jqueryui.com/demos/autocomplete/

<script> $(function() {     var availabletags = [         <?php         include 'connect.php';          $result=mysql_query("select * searchengine");          while ($row=mysql_fetch_assoc($result)){          $title=$row['title'];         $id=$row['id'];          echo "\"$title\",";          }           ?>     ];     $( "#tags" ).autocomplete({         source: availabletags      });  }); </script> 

p.s. use php inside jquery generate list of variables.

since don't know php, can't server-side code, should easy enough figure out once understand different data autocomplete can use.

for widget's data source, can specify array of objects label , value property. leverage value property store id database, , define event handler select event send user correct page.

here's example:

$("input").autocomplete({     source: [         { label: "home", value: '3' },         { label: "admin", value: '4' },         { label: "search", value: '55' }     ],     select: function(event, ui) {         /* prevent input being populated: */         event.preventdefault();         /* use ui.item.value access id */         window.location.href = "/index.php?id=" + ui.item.value;     } }); 

here's working (simpler) example: http://jsfiddle.net/j2jub/

as side note, consider using remote datasource option autocomplete provides if have ton of possible results.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -