I have a block of code that checks to see if a check box is checked or not, and assigns a value to a variable for saving to a MySQL table. There are approximately 8 of these boxes.
if ($("#amOld").is(":checked")) {
var amOldGuide=1;
} else {
var amOldGuide=0;
}
if ($("#folOld").is(":checked")) {
var folOldGuide=1;
} else {
var folOldGuide=0;
}
if ($("#tichOld").is(":checked")) {
var tichOldGuide=1;
} else {
var tichOldGuide=0;
}
if ($("#bookOld").is(":checked")) {
var bookOldGuide=1;
} else {
var bookOldGuide=0;
}
if ($("#nebOld").is(":checked")) {
var nebOldGuide=1;
} else {
var nebldGuide=0;
}
if ($("#sterOld").is(":checked")) {
var sterOldGuide=1;
} else {
var sterOldGuide=0;
}
if ($("#byteOld").is(":checked")) {
var byteOldGuide=1;
} else {
var byteOldGuide=0;
}
if ($("#ingOld").is(":checked")) {
var ingOldGuide=1;
} else {
var ingOldGuide=0;
}
I am using something similar for another set of check boxes later on in the project as well. As it sits, this works, but it is ugly. I feel that there must be a better way to write this that will be easier to maintain, and without having to repeat it later on. Should I be using a class or objects?
somevalue = +document.someform.somecheckbox.checked
. – Dagg 3 hours ago