Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
how to remove empty value in multiselect

HI how to remove empty value in multi select, bellow my code

    $(document).on('blur','.select2-search__field', function(e) {
    var current_select = window.localStorage.getItem("current_select");
    console.log($(this).val());
    if (current_select) {
        if ($(this).val()) {
        $("#"+current_select).append('<option value="'+$(this).val()+'" selected>'+$(this).val()+'</option>');
        //$("#"+current_select).val($(this).val());
        $("#"+current_select).trigger("change");
        }
    }
 });

when I enter new values that value appended it is working , but same time one empty value automatically comes so how can i removed please help me

Output is :

<option value=" " selected="selected"></option>
<option value=" 12345" selected="selected"> 12345</option>
<option value=" abcd" selected="selected">abcd </option> 

First value is empty, so how can I remove this.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

try this

$('select option')
.filter(function() {
    return !this.value || $.trim(this.value).length == 0;
})
   .remove();

or

$("#select option[value=' ']").remove();
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!