Why does checkbox gets checked on a click event for submit
I am using a jquery form to submit the interests for users. What I am
using is something like a checkbox value, they are seperate and I use
className to get their values.
The issue that I have to face is whether I select both of them or none of
them or just a single of them. I get them both checked when I click the
button that will submit the form using Ajax, so that results in an
opposite result.
Here is the code that I am using:
var getInterest = "";
if ($(".interestedInMale").attr('checked', 'checked') &&
$(".interestedInFemale").attr('checked', 'checked')) {
getInterest = "Females, Males";
} else if ($(".interestedInMale").attr('checked', 'checked')) {
getInterest = "Males";
} else if ($(".interestedInFemale").attr('checked', 'checked')) {
getInterest = "Females";
} else {
getInterest = "";
}
What should happen is that it should just provide me with the values, not
alter the values but what it does is opposite, it first changes the value
I mean checks them both, and then submits the form having the total value
Females, Males. And this is not what I want.
Below this code is the ajax submit block. And above this is the function
declaration as:
function submitThis() {
Any help for what I am doing wrong? Also, you can give me a better
suggestion for getting the values of Checkbox fields in jQuery Ajax.
No comments:
Post a Comment