• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Suggestion to video.derekallard.com

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
&lt;input type="hidden" id="id_cidade" name="id_cidade" value="" /&gt;

    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.

"I went to church incognito.
When everybody rose the Reverend Smith,
he recognized me and punched me in the nose."

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.