Shermaine Chaingan Shermaine Chaingan - 1 year ago 129
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...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download