CodeIgniter Forums
how to trap the primary key value for autocomple boxes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to trap the primary key value for autocomple boxes (/showthread.php?tid=23383)



how to trap the primary key value for autocomple boxes - El Forum - 10-09-2009

[eluser]bhakti.thakkar[/eluser]
Hi all,
i have created a page which has an auto complete box. i am using the code built by Derek Allard. its working great (Thanks a ton to him ). the only problem what i am facing is that, how will i get the id of the text that is getting selected?
for example, i am populating countries from the DB in the auto-complete box. if for example country 'US' is selected, the i want to trap id of US i.e '1' in a hidden field

i tried to modified control.js, but failed

How will i do that?

Thanks in anticipation


how to trap the primary key value for autocomple boxes - El Forum - 10-15-2009

[eluser]bhakti.thakkar[/eluser]
Hi all,
Still awaiting a reply on this....

Thanks


how to trap the primary key value for autocomple boxes - El Forum - 10-15-2009

[eluser]Colin Williams[/eluser]
The way I've seen it done before is to embed a macro in the value. Example:

Code:
<input type="text" class="autocomplete" value="Dynamic Value [id:322]" />

Then, on the submit event for the form, the JavaScript replaces the value with just the numeric ID. The downside is that the user is burdened and possibly confused with seeing the macro.

To "hide" the value elsewhere, you would need to do that on the event that the user selects an option from the autocomplete list. Not familiar with the control.js code but I'd imagine you can find the point where this happens and do your code there (just set the value in a hidden field, or hold it in a var then hijack the form value on submit).


how to trap the primary key value for autocomple boxes - El Forum - 10-15-2009

[eluser]bhakti.thakkar[/eluser]
Thanks Colin. Finally i could do it
i modified the control.js file and trapped the id. its working now fine

but one more confusion, what if i want more than one autocomplete ajax boxes in the same form??

Right now for one we are doing this:
<form id="function_search_form" method="post" action="<?=site_url('autocomplete/ajaxsearch');?>">
<div id="search">
&lt;INPUT TYPE="text" NAME="function_name_Readonly_ID" id="function_name_Readonly_ID"&gt;
Search by function name
&lt;input type="text" name="function_name" id="function_name"/&gt;
&lt;input type="submit" value="search" id="search_button"/&gt;
<div id="autocomplete_choices" class="autocomplete"></div>
</div>
&lt;/form&gt;

how will i add one more auto suggest here? i mean how can i pass different function to the autocomplete for different textboxes

Thanks


how to trap the primary key value for autocomple boxes - El Forum - 10-16-2009

[eluser]bhakti.thakkar[/eluser]
Yes ultimately i found an answer to this as well
i just added the textboxes with ofcourse unique ids and created different functions in the function_search.js and things are working fine

So this thread is solved