I have a form with several check boxes (id = chkmbrrole1 thru chkmbrrole17 and name = chkmbrrole[1] thru chkmbrrole[17]). In my Ready function when a User member name is selected via a select box, the user roles are retrieved. I then set the "checked" property to true if the user selected has that role. Like this: $("input:checkbox[name='chkmbrrole[1]']").prop('checked', true);
I also set the "defaultChecked" property to "true" for that user like this: $("input:checkbox[name='chkmbrrole[1]']").prop("defaultChecked", true)
or I can set the "defaultChecked" property like this: document.getElementById(chkmbrrole1).defaultChecked = true;
Both of the methods seem to work. I get no error messages in the console (using Chrome browser).
Later when I hit the Save button, I want to see if the particular checkbox has changed state from the original state, in my "button click" function.
To verify that the particular check box has or has not changed state, I check each checkbox using the following function code:
function sectionsupdated() {
$("input:checkbox").each(function(){
var chkname = $(this).prop("name");
var chkid = $(this).prop("id");
var chkrole = $(this).val();
var chkorigChkval = $(this).prop("defaultChecked");
var chknewChkval = $(this).prop("checked");
var chkorigValval = $(this).prop("defaultValue");
var chkdocval = document.getElementById(chkid).value;
var chgdrole = document.getElementById(chkid); var chgdroleval = document.getElementById(chkid).value;
console.log("Name of chkbox is: " + chkname );
console.log(" id of chkbox is: " + chkid + " chgdrole = " + chkrole + " And the Original DefaultChk Value is: " + chkorigChkval + " AND the Checked Value is: " + chknewChkval);
if (chkorigChkval != chknewChkval) {
nbrsectionsupdated = 1;
return nbrsectionsupdated;
}
}
}
When I look at the Console, for the first of the check boxes I get: Name of chkbox is: chkmbrrole[1] id of chkbox is: chkmbrrole1 chgdrole = 1 And the Original DefaultChk Value is: false AND the Checked Value is: true
My problem is that although I did set the defaultChecked property, it seems to think I didn't.
Need some help figuring out what I did wrong.
If code is needed, I can provide what ever is needed to solve this problem.
(But the full code is very long. LOL)
Thanks in Advance.
Aucun commentaire:
Enregistrer un commentaire