Skip select option if default value come

Gerardo

Im working into full calendar add_event and I have something like his:

$('#event_add').unbind('click').click(function () {
    var title =
       $('#lstProveedor option:selected').html() +
        ' - ' +
        $('#lstcuadrilla option:selected').html() +
        ' - ' +
        $('#lstSucursal option:selected').html() +
        ' - ' +
        $('#lstRegion option:selected').html() +
        ' - ' +
        $('#lstSolicitud option:selected').html();
    addEvent(title);
});

For example: if selected value of $('#lstProveedor option:selected').html() +' - ' is "select an option" don´t count it, just skip can I do that? Regards

Prashant Shirke

You can try checking the index, if its 0 then its default value in your case.

$('#event_add').unbind('click').click(function () {
  var title = "";
  if($('#lstProveedor').prop('selectedIndex') !== 0){
    title += $('#lstProveedor option:selected').html() + "-";
  }
   if($('#lstcuadrilla').prop('selectedIndex') !== 0){
    title += $('#lstcuadrilla option:selected').html() + "-";
  }
   if($('#lstSucursal').prop('selectedIndex') !== 0){
    title += $('#lstSucursal option:selected').html() + "-";
  }
  if($('#lstRegion').prop('selectedIndex') !== 0){
    title += $('#lstRegion option:selected').html() + "-";
  }
  if($('#lstSolicitud').prop('selectedIndex') !== 0){
    title += $('#lstSolicitud option:selected').html() + "-";
  }
  title= title.slice(0,-1);
  addEvent(title);
});

Or you can simply add one common class to every select you need to consider for concatenation and then can use code like following!

$('#event_add').off('click').click(function () {
  var title = "";
  $(".commonclass").each(function(i,e){
      if($(this).prop('selectedIndex') !== 0){
        title += $(this).find("option:selected").text() + "-";
      }
  });
  title= title.slice(0,-1);
  addEvent(title);
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Set default value of select to null option

From Dev

Select Option Value return Integer by default

From Dev

Codeigniter in select option default value not working

From Dev

how to set a default value for select option

From Dev

Select Option Value return Integer by default

From Dev

Default Select Option Based on Input Value

From Dev

The default value is not ? object:null ? in select option Angularjs

From Dev

Default value to select option menu is not recognized

From Dev

Foreach skip option value

From Dev

CakePHP2 - Default value for input - select with option multiple

From Java

how to use ng-option to set default value of select element

From Dev

Make the default option of select tag to be of current value of name in Rails

From Dev

set default option in a select via ng-init on VALUE and not INDEX

From Dev

Unable to get value of default option in select2 jquery

From Dev

AngularJS - ng-repeat default value for select option

From Java

default select option as blank

From Dev

HTML <select> default option

From Dev

default setting for option select

From Dev

default value in option

From Dev

AngularJS select creates option with value "? object:null ?" and doesn't use empty default option when bound to null

From Dev

Laravel - Select - set Default option

From Dev

Laravel Option Select - Default Issue

From Dev

Laravel Option Select - Default Issue

From Dev

add default option to angularjs select

From Dev

change color of default option in select

From Dev

Jquery select option default option text

From Dev

Select option by value jquery

From Dev

is a select option with no value, valid?

From Dev

select option value jquery

Related Related

HotTag

Archive