hari
hari

Reputation: 103

Trying to separate four items with comma in Dropdown list

Trying to separate four items with comma which is bind in item from database on success of jQuery Ajax. html side

<td><select class='form-control' id='Certific'><option value='' disabled='disabled' selected='selected'>Please select a name</option></select></td>

on success of jQuery Ajax function I am appending it option like this way.

success: function (r) {
    var Certific = $("[id*=Certific]");
    $.each(r.d, function () {
        Certific.append($("<option></option>").val(this['CODE_VALUE']).html([this['CODE_VALUE'], this['CODE_DESC'], this['CODE_SUB_VALUE'], this['CODE_SUB_DESC']]));
    });
}

o/p is appearing like this

enter image description here

I want to arrange dropdown like :127,Coil,wt,1KGS and remove second dropdown item "Please select a name".

Upvotes: 0

Views: 112

Answers (2)

Charanraj Golla
Charanraj Golla

Reputation: 1102

For the first part simply remove the value "Please select a name" from the select tag.

<select class='form-control' id='Certific'><option value='' disabled='disabled' selected='selected'></option></select>

For adding comma you can try the following. (Code is not tested)

success: function (r) {
var Certific = $("[id*=Certific]");
var option = $('<option/>');

$.each(r.d, function () {
    var value= this['CODE_VALUE'] +', ' + this['CODE_DESC'] +', ' + this['CODE_SUB_VALUE'] +', ' + this['CODE_SUB_DESC'];
    option.attr({ 'value': this['CODE_VALUE'] }).text(value);
    $(option).append(option);
});
$(Certific).append(option);
}    

Upvotes: 1

AlleXyS
AlleXyS

Reputation: 2598

Change tour first option like that:

<option value="" disabled selected>Select your option</option>

Upvotes: 0

Related Questions