Part of the EllisLab Network
   
 
Suggestion to video.derekallard.com
Posted: 19 September 2007 09:48 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  298
Joined  09-11-2007

After saw the video, a suggestion came to me. How can i pick an id from selected item on li list?

My final code is about that:

The method in my controller

$output = '<ul>';
foreach (
$cidades->result() as $cidade)
{
    $output
.= '<li id="'.$cidade->id_cidade.'">'.$cidade->nome_cidade.' - '.$cidade->sigla_estado.'</li>';
}
$output
.= '</ul>';
echo
$output;

Where $cidade->id_cidade is the unique id that i want do see after

My view file

<input type="hidden" id="id_cidade" name="id_cidade" value="" />

    new
Ajax.Autocompleter('txt_cidade', 'resultados', 'cidades/lista_cidade/', {afterUpdateElement : setCidadeId})
        
    function
setCidadeId(inputField, selectedItem)
    
{
        
$('id_cidade').value = selectedItem.id;
    
}

So, when i post my form, i’ll have a hidden field called cidade_id that contains the unique id!!

The video, all is correct, but, in my case (and i think some other users case), you need the id, not the text in the input field.

[]‘s
“I went to church incognito.
When everybody rose the Reverend Smith,
he recognized me and punched me in the nose.”

 Signature 

cool mad
Rafael
Last.fm
Twitter

“Because they’re stupid, that’s why. That’s why everybody does everything!”

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120500 Total Logged-in Users: 35
Total Topics: 126572 Total Anonymous Users: 5
Total Replies: 665450 Total Guests: 359
Total Posts: 792022    
Members ( View Memberlist )