I am tring to get the state of the checkbox from an html table in javascript so I can then use it to edit information on the following page, and then save to mysql database.
When I click on the edit button it runs the following script and then go to the edit page where I need a 1 or 0 depending on the checkbox state to carry over, but it does not or at least in the format I need.
Using javascript Alert(); it displays the entire html input line code with checked=’checked’ at the end. When I click the edit button on a record in the html table that has the checkbox set in the database.
How can I get what I need?
here is the script code.
<script>
function editsubcategory(element, value) {
var _$index = (element.parentNode.parentNode.rowIndex)
var myTab = document.getElementById('subcategorytable');
var objCells = myTab.rows.item(element.parentNode.parentNode.rowIndex).cells;
var _$subCategoryID = objCells.item(0).innerHTML; // categoryID
var _$subCategoryName = objCells.item(1).innerHTML; // categoryName
var _$subCategoryDescription = objCells.item(2).innerHTML; // categoryDescription
var _$subCategoryMain = objCells.item(3).innerHTML; // subCategoryMain
var _$subCategoryType = objCells.item(4).innerHTML; // subCategoryType
var _$subCategoryBudget = objCells.item(5).innerHTML; // subCategoryType
var _$subCategoryDiscretionary = objCells.item(6).innerHTML; // subCategoryType
var _$btn = value; // button
// alert(_$subCategoryID);
// alert(_$subCategoryName);
// alert(_$subCategoryDescription);
// alert(_$subCategoryMain);
// alert(_$subCategoryType);
// alert(_$subCategoryBudget);
// alert(_$subCategoryAccount);
alert(_$subCategoryDiscretionary);
// alert(_$btn);
window.location.href = "edit-subcategory.php?subCategoryID=" + _$subCategoryID
+ "&btn=" + _$btn
+ "&subCategoryName=" + _$subCategoryName
+ "&subCategoryDescription=" + _$subCategoryDescription
+ "&subCategoryMain=" + _$subCategoryMain
+ "&subCategoryType=" + _$subCategoryType
+ "&subCategoryBudget=" + _$subCategoryBudget
+ "&subCategoryDiscretionary=" + _$subCategoryDiscretionary;
};
</script>
I have tried different ways to get the state, but nothing has worked. I think the issue is with what is being returned from the
var _$subCategoryDiscretionary = objCells.item(6).innerHTML;
line but I have no idea how to get the state.
This 6th item contains a checkbox.
I just want the variable _$subCategoryDiscretionary to be either a 1 or 0, true or false, checked or unchecked so i can perform an IF statement on it.