Autocomplete text box using Jquery
In this session,i'm going to explain about Autocomplete Textbox using Jquery.We may have met lot of situations for provide suggestions to users while they are typing .It will be more helpful for them to identify the datas easily.Time will be reduced by this.we can accomplish this through Lot of jquery plugins .Here i have used one jquery plugin with the link
https://www.jqueryscript.net/form/Autocomplete-Dropdown-List-Plugin-jQuery.html
This plugin must be included before proceed the below code.So now we can see how to make autocomplete textbox by using this plugin.
In my case i have use one html select control for express this plugin feature.Here i have loaded dynamic data and static as well.
1.Dynamic data
Jquery
$.ajax({
type: 'post',
url: 'type your url',
data: {parameters},
dataType: 'json',
success: function (data) {
if (data.length != 0) {
var list =''';
$.each(data, function (key, data)
{
list += "<option value='" + data.value + "'>" + data.text + "</option>";
});
$('#test').empty().append(list);
$('#test').autocompleteDropdown({ customPlaceholderText: "Search..." });
}
},
error: function () { }
});
HTML
<select id="test" class="form-control"></select>
2.Static data
Jquery
$('#test').autocompleteDropdown({ customPlaceholderText: "Search..." });
HTML
<select id="test" class="form-control">
<option value ="0" >Apple</option>
<option value ="1" >Orange</option>
<option value ="2" >Mango</option>
</select>
We can load data by two ways such as dynamic and static.As per your convenient select the suitable one.
I hope it will be helpful for you.
https://www.jqueryscript.net/form/Autocomplete-Dropdown-List-Plugin-jQuery.html
This plugin must be included before proceed the below code.So now we can see how to make autocomplete textbox by using this plugin.
In my case i have use one html select control for express this plugin feature.Here i have loaded dynamic data and static as well.
1.Dynamic data
Jquery
$.ajax({
type: 'post',
url: 'type your url',
data: {parameters},
dataType: 'json',
success: function (data) {
if (data.length != 0) {
var list =''';
$.each(data, function (key, data)
{
list += "<option value='" + data.value + "'>" + data.text + "</option>";
});
$('#test').empty().append(list);
$('#test').autocompleteDropdown({ customPlaceholderText: "Search..." });
}
},
error: function () { }
});
HTML
<select id="test" class="form-control"></select>
2.Static data
Jquery
$('#test').autocompleteDropdown({ customPlaceholderText: "Search..." });
HTML
<select id="test" class="form-control">
<option value ="0" >Apple</option>
<option value ="1" >Orange</option>
<option value ="2" >Mango</option>
</select>
We can load data by two ways such as dynamic and static.As per your convenient select the suitable one.
I hope it will be helpful for you.
Comments
Post a Comment