I have implemented Autocomplete textbox in my asp.net MVC3 application, but I am unable to show loading image inside textbox during search. My code is
Javascript
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("#txtPONO").autocomplete({
source: "/Transection/GetPONO",
minLength: 2,
select: function (event, ui) {
$("#hdnPurContID").val(ui.item.id);
}
});
});
</script>
View
<div style="float: left; padding: 9px 5px 5px 5px; width: 80px; vertical-align: middle"
class="fieldHead">
Enter @Html.LabelFor(l => l.PurchaseContract.AOPLPONO)
</div>
<div style="float: left; width: 200px; padding: 5px 0px 5px 0px;">
@Html.TextBoxFor(m => m.PurchaseContract.AOPLPONO, new { @id = "txtPONO", @class = "textbox", @style = "width:100%" })
</div>
<div style="float: left; width: 50px; padding: 4px 0px 0px 5px;">
<img alt="search" src="../../Content/images/Search.png" />
@Html.HiddenFor(model => model.PurchaseContract.PurContID, new { @id = "hdnPurContID" })
</div>
I want to show a small loading image inside textbox on right side
Add a css class like this.
.loading
{
background:url('path to your image') no-repeat right center;
}
Now trigger to the search option and open options for autocomplete
$("#txtPONO").autocomplete({
source: "/Transection/GetPONO",
minLength: 2,
select: function (event, ui) {
$("#hdnPurContID").val(ui.item.id);
},
search: function(){$(this).addClass('loading');},
open: function(){$(this).removeClass('loading');}
});
OR
Even better solution would be just using the css class
.ui-autocomplete-loading { background:url('img/loading.gif') no-repeat right center }
jQuery ui-autocomplete-loading
automatically runs the loading image for the duration of loading
Hope it helps
You can do it like this-
.loadinggif {
background:url('http://www.hsi.com.hk/HSI-Net/pages/images/en/share/ajax-loader.gif') no-repeat right center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input id='inputsource' />
<br>
<button onclick="$('#inputsource').addClass('loadinggif');">Show Loading</button>
<br>
<button onclick="$('#inputsource').removeClass('loadinggif');">Hide Loading</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With