TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhilash J A
534
2.4k
597.2k
jQuery checkbox always returns 'undefined' using foreach
Jan 13 2016 10:23 AM
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 == "
undefined
Daytime–Weekday(06:26:00-17:25:00)") {
$('#daysTD').html('')
$('#daysTD').html('<ul><li><input type="checkbox" class="chkWeek" id="chkAllWeek" checked />All</li><li><input type="checkbox" checked value="Mon" name="Monday" class="chkWeek" id="chkWeek1" />Monday</li><li><input type="checkbox" checked value="Tue" name="Tuesday" class="chkWeek" id="chkWeek1" />Tuesday</li><li><input type="checkbox" checked value="Wed" name="Wednesday" class="chkWeek" id="chkWeek1" />Wednesday</li><li><input type="checkbox" checked value="Thu" name="Thursday" class="chkWeek" id="chkWeek1" />Thursday</li><li><input type="checkbox" checked value="Fri" name="Friday" class="chkWeek" id="chkWeek1" />Friday</li></ul>')
}
else if (daypartText == "
undefined
Daytime-Weekend(06:26:00-17:25:00)") {
$('#daysTD').html('');
$('#daysTD').html('<ul><li><input type="checkbox" checked class="chkWeek" id="chkAllWeek" />All</li><li><input type="checkbox" checked value="Sun" name="Sunday" class="chkWeek" id="chkWeek1" />Sunday</li><li><input type="checkbox" checked value="Sat" name="Saturday" class="chkWeek" id="chkWeek1" />Saturday</li></ul>');
}
}
else {
$('#daysTD').html('');
$('#daysTD').html('<ul><li><input type="checkbox" checked class="chkWeek" id="chkAllWeek" />All</li><li><input type="checkbox" checked value="Sun" name="Sunday" class="chkWeek" id="chkWeek1" />Sunday</li><li><input type="checkbox" checked value="Mon" name="Monday" class="chkWeek" id="chkWeek1" />Monday</li><li><input type="checkbox" checked value="Tue" name="Tuesday" class="chkWeek" id="chkWeek1" />Tuesday</li><li><input type="checkbox" checked value="Wed" name="Wednesday" class="chkWeek" id="chkWeek1" />Wednesday</li><li><input type="checkbox" checked value="Thu" name="Thursday" class="chkWeek" id="chkWeek1" />Thursday</li><li><input type="checkbox" checked value="Fri" name="Friday" class="chkWeek" id="chkWeek1" />Friday</li><li><input type="checkbox" checked value="Sat" name="Saturday" class="chkWeek" id="chkWeek1" />Saturday</li></ul>')
}
});
});
And 'chkdaypart' id contain list of checkboxlist which return list of names like this:-
<ul>
<li>
<input type="checkbox" id="chkAlldaypart" />All</li>
@foreach (var items in ViewData["daypart"] as List<SelectListItem>)
{
<li>
<input type="checkbox" name="@items.Text" value="@items.Value" class="chkclass_daypart" id="chkdaypart"/>
@items.Text
</li>
}
</ul>
Reply
Answers (
5
)
Add Burn Plugin In Page
Add new row with default parameter at first cell in jqgrid