Reputation: 5071
Here is my code. This code is not working in mozilla firefox browser.
My Html
<input class="staff_check" name="select_staff" type="checkbox" value="@Model.Caregivers[i].AgencyUserID" />
Script
var selected_staff = [];
var selected_staff_names = [];
$('input[name="select_staff"').change(function () {
console.log('ds');
if (this.checked) {
selected_staff.push($(this).val());
selected_staff_names.push('<span class="selected_staff">' + $(this).parent('label').text().trim() + '</span>');
}
else {
var idx = $.inArray($(this).val(), selected_staff);
if (idx > -1) {
selected_staff.splice(idx, 1);
selected_staff_names.splice(idx, 1);
}
}
});
This works fine in google chrome. But it'nt work in mozilla firefox.
Upvotes: 1
Views: 1537
Reputation: 100195
you missed closing square bracket ']
', change:
...
$('input[name="select_staff"').change(function () {
....
to
...
$('input[name="select_staff"]').change(function () {
...
Upvotes: 2
Reputation: 1738
Instead of change()
function, try click()
:
var selected_staff = [];
var selected_staff_names = [];
$('input[name="select_staff"]').click(function () {
console.log('ds');
if (this.checked) {
selected_staff.push($(this).val());
selected_staff_names.push('<span class="selected_staff">' + $(this).parent('label').text().trim() + '</span>');
}
else {
var idx = $.inArray($(this).val(), selected_staff);
if (idx > -1) {
selected_staff.splice(idx, 1);
selected_staff_names.splice(idx, 1);
}
}
});
Upvotes: 1