jQuery Autocomplete using extraParams to pass additional GET variables
Posted
by paperclip
on Stack Overflow
See other posts from Stack Overflow
or by paperclip
Published on 2010-04-28T08:32:45Z
Indexed on
2010/04/28
9:13 UTC
Read the original article
Hit count: 939
I am referring specifically to the jQuery Autocomplete v1.1 plugin by Jörn Zaefferer [source: http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/] as there seems to be quite a few variations of this plugin.
I'm trying to pass additional parameters to the server when the user starts typing because I have multiple fields that I want autocomplete to provide suggestions for.
In addition to the query, I want to send the input name attribute to the server but I can't seem to use $(this).attr('name') within the extraParams.
My jQuery:
$('.ajax-auto input').autocomplete('search.php', {
extraParams: {
search_type: function(){
return $(this).attr('name');
}
}
})
This is my HTML.
<form method="post" action="#" id="update-form" autocomplete="off">
<ol>
<li class="ajax-auto">
<label for="form-initials">Initials</label>
<input type="text" id="form-initials" name="initials" />
</li>
<li class="ajax-auto">
<label for="form-company">Company</label>
<input type="text" id="form-company" name="company" />
</li>
</ol>
</form>
Any suggestions?
© Stack Overflow or respective owner