By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,043 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,043 IT Pros & Developers. It's quick & easy.

Finding the id of a jquery autocomplete input from within the onItemSelect call

P: 15
i have this,

Expand|Select|Wrap|Line Numbers
  1. $(function() {
  2.        $('#input').autocomplete('test.php', {json: true});
  3.      });
  4.  
that bring back values from the database here is my php section

Expand|Select|Wrap|Line Numbers
  1. $result = mysqli_query($db,$query);
  2.  
  3. while( $row = mysqli_fetch_array($result) )
  4. {    
  5. $aResults[] = array( "id"=>($row['s_id']) ,"value"=>($row['s_last']), "info"=>($row['s_first']) );
  6. }
  7.  
  8. $return = array();
  9.  
  10. foreach ($aResults as $key => $res) {
  11.      $return[] =$res['value'] . ' , ' . $res['info'];
  12.  
  13. }
  14.  
  15.  
  16. echo json_encode($return);
  17.  
  18.  
  19.  
  20.         }
  21.     }
  22. }
  23.  
i would like, when i select a name from the auto suggest to be able to have the id be filled in a input text area...

uncle Google says this, but i am having a hard time implementing it.

Expand|Select|Wrap|Line Numbers
  1. myCallback = function(li, $input) {
  2.     // I need to refer to the appropriate "myXxxInput" here
  3.     alert($input.attr('id'));
  4. }
  5.  
  6. setup = function() {
  7.     setupInput($('#myFirstInput'));
  8.     setupInput($('#mySecondInput'));
  9. }
  10.  
  11. function setupInput($input) {
  12.     $input.autocomplete('blah.php', {onItemSelect: function(li) {
  13.         myCallback(li, $input);} });
  14. }
  15.  
  16.  
Nov 18 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.