Shermaine Chaingan Shermaine Chaingan - 11 months ago 70
jQuery Question

set empty on first value in combobox

How can I set the first value to

? I used this codes but it does not work? How will I set a placeholder on combobox? Thank you in advance.

<select class="ddlASN"></select>

var result = 'a,b,c,d';

$('.ddlASN').html($.map(result.split(','), function(item) {
return $('<option></option>').val('').html('')[0].outerHTML
return $('<option></option>').val(item).html(item)[0].outerHTML

Answer Source

You can try this.

    var result = 'a,b,c,d';

// placeholder option
var dd_content = '<option>-- Select an option --</option>';

// add rest of the options','), function(item) {
  dd_content += '<option value="'+item+'">'+item+'</option>';


It will prevent from getting values repeated after the submition.

If it doesn't work then please do tell what actually happens after submitting the form. Are the new values getting assigned to the combobox or not...