Kalashir Kalashir - 2 months ago 7
Javascript Question

On clicking on close button of page i want to clear all selectbox value

I have 3 selectbox on my page and onClick of close button I want to clear all the selectbox which are under the class

.popup
.

Below is my code to clear fields.

clearText: function() {
$('.popupBody input').val('');
$('.popupBody select').val('');
$('.popupForm').find('.errmsgActive').removeClass('errmsgActive');
$('.popupForm').find('.errmsg').html('');
}


For clearing all select boxes inside
.popupBody
class, I am using below code.

$('.popupBody select').val('');

Answer

For clearing selection made in select2 select box you can try following approach:

$('.popupBody select').each(function(){
    //iterate over all the select boxes one by one
    $(this).select2("val", ""); //clearing the selection made
});
Comments