• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AJAX and autocompletion

#1
[eluser]Unknown[/eluser]
Apologies for cross posting but as I haven't had a reply on the original post I thought I would start a new post.

I have successfully taken Derek’s code (http://video.derekallard.com/) to create a dynamic information retrieval form. It works great. I now want to add some extra functionality.

I’m building a form where a user will first select their city from a drop down list and then start typing into a text box their town/city which will then automatically appear. Thus, the dynamic retrieval of cities will only select cities from the country selected.

I need to know how to pass the select box data (country) through AJAX along with what the user types into the text box (city/town). I’m guessing I need to add some code to function_search.js in the javascript folder, but am not sure…

I'm not confined to using script.aculo.us so if you've got a solution using JQuery or something else then let me know.

Any pointers would be greatly received.

Thanks
Rob

#2
[eluser]sszynrae[/eluser]
quick guess from description: pass $('selectboxid').value() as one of the parameters in the ajax.autocompleter and modify your get_searchresults function to add a $this->db->where() on that extra input.

#3
[eluser]Unknown[/eluser]
Thanks for that...

Here is the code in the javascript file:
window.onload = function () {
new Ajax.Autocompleter("function_name", "autocomplete_choices", base_url+"application/ajaxsearch/", {});I think something needs to go in here?

$('function_search_form').onsubmit = function () {
inline_results();
return false; }
}

function inline_results() {
new Ajax.Updater ('function_description', base_url+'application/ajaxsearch', {method:'post', postBody:'description=true&function;_name='+$F('function_name')});
new Effect.Appear('function_description');

}

#4
[eluser]sszynrae[/eluser]
try just changing the postbody line to:
postBody:‘description=true&function;_name=’+$F(‘function_name’)+'city='+$('selectboxid').value});

then it should be available in your controller function as $_POST['city']


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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