I am trying to implement a code to get checkbox list attr('name') while return 'undefind' word. What is the reason for this and How this one remove?
jQuery(document).on("change", "#chkdaypart", function () {
var daypartText;
$(this).each(function (e) {
if (this.checked) {
daypartText = daypartText + $(this).attr('name');
if (daypartText == "undefinedDaytime–Weekday(06:26:00-17:25:00)") {
$('#daysTD').html('')
$('#daysTD').html('
}
else if (daypartText == "undefinedDaytime-Weekend(06:26:00-17:25:00)") {
$('#daysTD').html('');
$('#daysTD').html('
}
}
else {
$('#daysTD').html('');
$('#daysTD').html('
}
});
});
var daypartText;
$(this).each(function (e) {
if (this.checked) {
daypartText = daypartText + $(this).attr('name');
if (daypartText == "undefinedDaytime–Weekday(06:26:00-17:25:00)") {
$('#daysTD').html('')
$('#daysTD').html('
- All
- Monday
- Tuesday
- Wednesday
- Thursday
- Friday
}
else if (daypartText == "undefinedDaytime-Weekend(06:26:00-17:25:00)") {
$('#daysTD').html('');
$('#daysTD').html('
- All
- Sunday
- Saturday
}
}
else {
$('#daysTD').html('');
$('#daysTD').html('
- All
- Sunday
- Monday
- Tuesday
- Wednesday
- Thursday
- Friday
- Saturday
}
});
});
And 'chkdaypart' id contain list of checkboxlist which return list of names like this:-
All
@items.Text
@foreach (var items in ViewData["daypart"] as List
{
}



Manas MohapatraRank #182 · 13.2K reputationPosted Jan 17, 2016, 9:37 PM EST
Manas MohapatraRank #182 · 13.2K reputationPosted Jan 13, 2016, 6:54 AM EST
Abhilash J ARank #1,243 · 1.4K reputationPosted Jan 17, 2016, 7:10 PM EST
The daypartext is carry the value from this checkboxlist using jquery
All
@foreach (var items in ViewData["daypart"] as List
{
@items.Text
}
Abhilash J ARank #1,243 · 1.4K reputationPosted Jan 17, 2016, 9:24 PM EST
All
@foreach (var items in ViewData["daypart"] as List
{
@items.Text
}
always daypartText contain 'undefined'. how to avoid this one from daypartText.
Actually I want,
daypartText="Daytime–Weekday(06:26:00-17:25:00)";
not like this,
daypartText = "undefinedDaytime–Weekday(06:26:00-17:25:00)";