views:

97

answers:

2

I want to convert the following prototype js to jquery js.

Can anyone help me please?

Thanks in advance.

window.onload = function () {
    new Ajax.Autocompleter("function_name", "autocomplete_choices", 
    base_url+"application/ajaxsearch/", {});

    $('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');

}

HTML is the following

<form id="function_search_form" method="post" 
action="http://127.0.0.1/ci_sample/index.php/application/search"&gt;
    <div>
        <label for="function_name">Search by function name </label>
        <input type="text" name="function_name" id="function_name" />
        <input type="submit" value="search" id="search_button" />

        <div id="autocomplete_choices" class="autocomplete"></div>
    </div>
    </form>
+1  A: 

You'll need to get an Autocomplete Plugin for the first part, but the rest follows:

$(function(){

  // without knowing the return data, I'm shooting in the dark here
  $.post(base_url+"application/ajaxsearch/", function(results) {
    // pass results (html?) into our 'autocomplete' DIV
    $("#autocomplete_choices").html(results);
  });

  // Handle the form submission
  $("#function_search_form").submit(function(){
    inline_results();
    return false;
  });

});

function inline_results() {
  $.post(base_url+"application/ajaxsearch", {'description':true, 'function_name':$("#function_name").val()}, function(results){
    $("#function_description").html(results).fadeIn("slow");
  });
}
Jonathan Sampson
A: 

Probably lots of other ways, but here's what I got.

You might need a plugin for the autocompleter like this: http://docs.jquery.com/Plugins/Autocomplete

The rest of the code would look something like this:

$(document).ready(function(){
 //auto completer code

 $('#function_search_form').submit(function(){
  inline_results();
  return false;
 });
});

function inline_results() {
 $("#function_description").load(base_url + 'application/ajaxsearch', 'description=true&function_name=' + $('#id-of-function_name-element').val());
 $("#function_descritpion").show('normal');
}

You should also consider using .serialize() for the form values.

fehays