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
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.
Comments