在这里,我有带有复选框的树视图。我的问题是如何设置等于“y”的选中复选框以及未选中的复选框等于“n”的条件。我必须在数据库中更新 chekbox 的值,该列处于活动状态,包含两个值,即“y”和“n”。我在 javaScript 中使用 AJAX。应该在数据库中选中复选框将获得“y”,未选中复选框将获得“n”。但是现在,我目前只是在数据库中保存等于“y”的选中复选框。任何人都有建议,最好的方法是什么?供您参考,我正在使用 treeview Kendo UI。
更新.php
function deleteTemplate(){
global $ehorsObj;
$employeeID = $_SESSION['employeeID'];
$propertyID = $_SESSION['propertyID'];
$id = (isset($_POST['id']) ? $_POST['id'] : '');
$progid = (isset($_POST['progid']) ? $_POST['progid'] : '');
$sqlDelete = "DELETE FROM tblHrsPositionProgramTemplate
WHERE hrsPositionID = '".$id."'";
$ehorsObj->ExecuteData($sqlDelete, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
for($x=0; $x< sizeof($progid); $x++ )
{
$positionTemplateID = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplate");
$sqlAdd = "INSERT INTO tblHrsPositionProgramTemplate
SET positionTemplateID = '" . $positionTemplateID . "',
programID = '" . $progid[$x] . "',
hrsPositionID = '" . $id . "',
propertyID = '" . $propertyID . "',
employeeID = '" . $employeeID . "',
dateTimeEmployee = NOW() ";
$ehorsObj->ExecuteData($sqlAdd, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
$positionTemplateIDLog = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplateLog");
$sqlAddLog = "INSERT INTO tblHrsPositionProgramTemplateLog
SET positionTemplateIDLog = '" . $positionTemplateIDLog . "',
positionTemplateID = '" . $positionTemplateID . "',
programID = '" . $progid[$x] . "',
hrsPositionID = '" . $id . "',
propertyID = '" . $propertyID . "',
employeeID = '" . $employeeID . "',
dateTimeEmployee = NOW() ";
$ehorsObj->ExecuteData($sqlAddLog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}}
AJAX JavaScript
//AJAX call for button
$("#primaryTextButton").kendoButton();
var button = $("#primaryTextButton").data("kendoButton");
button.bind("click", function(e) {
var test = $("#dropdown").data("kendoDropDownList").value();
if(test == ""){
KendoAlert("Please select position");//dropdown
}
else{
$.ajax({
url: "../DesignationProgramTemplate/getTempJson.php",
type: "POST",
data: {
method: "addTemplate" ,
id: test,
progid: array
},
success: function () {
KendoAlert('Success'); }});
}
});
您可以轻松获取是否选中复选框(例如,请参阅此内容),并在您的 ajax 中发送您的复选框的名称以及值(真/假)。
<input type='checkbox' name='checkbox1' class='my-checkboxes'/>Checkbox 1
<script>
$(document).ready(
function () {
$(".my-checkboxes").on('change', function () {
let checkboxIsChecked = ($(this).is(':checked'));
let checkboxName = $(this).attr('name');
//do your ajax post based on the checkbox name and value
console.log(checkboxIsChecked, checkboxName);
});
}
);
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句