Data binding to Html Select box dynamically by using Jquery.

Posted by Udaysimha under jQuery on 4/6/2012 | Points: 10 | Views : 13675 | Status : [Member] | Replies : 5
Hi All,

In my application i have a requirement that Html select box should be populated dynamically using Jquery. I did it, but problem is, space is getting adding between two items, for example like bellow:

One

Two

Three

Please let me know the reasons with solutions to avoid that. any help would be appreciated.

uday


Responses

Posted by: Swapnil on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
Can you please post the JQuery code which you have used to populate the HTML select box?

Thanks and Regards,
Swapnil

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
Caan you post the JQuery code which code you have used to the html select box?

Thanks & Regards
Hari

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Udaysimha on: 4/7/2012 [Member] Starter | Points: 25

Up
0
Down
var url = '<%: Url.Action("GetCountrieslist","Settings") %>'
$.ajax({
cache: false,
type: "POST",
url: url,
data: '',
dataType: "json",
success: function (data) {
$.each(data, function (ind) {

var contrynames = data[ind].CountryName.trim().toString();

$("#sltrtcnty").append('<option value=' + contrynames + '>' + contrynames + '<option>');
});

},
error: function (xhr) {
alert('Error occured');
}
});

uday

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Udaysimha on: 4/7/2012 [Member] Starter | Points: 25

Up
0
Down
var url = '<%: Url.Action("GetCountrieslist","Settings") %>'
$.ajax({
cache: false,
type: "POST",
url: url,
data: '',
dataType: "json",
success: function (data) {
$.each(data, function (ind) {
var contrynames = data[ind].CountryName.trim().toString();

$("#sltrtcnty").append('<option value=' + contrynames + '>' + contrynames + '<option>');
});

},
error: function (xhr) {
alert('Error occured');
}
});

uday

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Swapnil on: 4/7/2012 [Member] Starter | Points: 25

Up
0
Down
It seems your Jquery code is fine. Can you check the data (from both server and client side) return in JSON is not contains any blank records?

Thanks and Regards,
Swapnil

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response