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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bytesFTW99
    New Member
    • Nov 2008
    • 15

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

    i have this,

    Code:
    $(function() {
           $('#input').autocomplete('test.php', {json: true});
         });
    that bring back values from the database here is my php section

    Code:
    $result = mysqli_query($db,$query);
    
    while( $row = mysqli_fetch_array($result) )
    {	
    $aResults[] = array( "id"=>($row['s_id']) ,"value"=>($row['s_last']), "info"=>($row['s_first']) );
    }
    	
    $return = array();
    
    foreach ($aResults as $key => $res) {
    	 $return[] =$res['value'] . ' , ' . $res['info'];
    	 
    }
    
    
    echo json_encode($return);
    
    
    
    		}
    	}
    }
    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.

    Code:
    myCallback = function(li, $input) {
        // I need to refer to the appropriate "myXxxInput" here
        alert($input.attr('id'));
    }
    
    setup = function() {
        setupInput($('#myFirstInput'));
        setupInput($('#mySecondInput'));
    }
    
    function setupInput($input) {
        $input.autocomplete('blah.php', {onItemSelect: function(li) {
            myCallback(li, $input);} });
    }
Working...