admin管理员组文章数量:1122832
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.
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.
Share Improve this question edited Nov 22, 2024 at 2:01 Shadow 34.2k10 gold badges63 silver badges72 bronze badges asked Nov 22, 2024 at 1:40 newtowebappnewtowebapp 14 bronze badges 3 |1 Answer
Reset to default 0If you want the checked value and not the html, then get the .checked value not the .innerHTML
var _$subCategoryDiscretionary = objCells.item(6).checked;
本文标签: javascriptHow to get TRUEFALSE or CHECKEDUNCHECKED or 10 from html checkboxStack Overflow
版权声明:本文标题:javascript - How to get TRUEFALSE or CHECKEDUNCHECKED or 10 from html checkbox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736306193a1932867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
href
value for<a>
. Post what the rendered HTML looks like for a row<tr><td>...</td><td>...,...</tr>
. – zer00ne Commented Nov 22, 2024 at 2:31td
. TryobjCells.items(6).querySelector("input[type='checkbox']").checked
– James Commented Nov 22, 2024 at 4:25