我有一个视图,它计算要编辑的条目,使用 javascript 删除。id 是根据勾选的复选框计算的,并存储在一个数组中,该数组需要发送到控制器方法以进行编辑或删除...我在某处读到理想情况下不应将变量从视图发送到 Codeigniter 中的控制器。我该怎么做?
看法
function checkedAll() {
var rowlength=document.getElementById("check").rows.length;
z=document.getElementById("check").getElementsByTagName("input")[0].checked;
for(var i=1;i<rowlength-1;i++)
{
document.getElementById("check").getElementsByTagName("input")[i].checked = z;
}
}
function del(){
var rowlength=document.getElementById("check").rows.length;
var id = new Array();
for(var i=1;i<rowlength-1;i++)
{
var t = document.getElementById("check").getElementsByTagName("input")[i].checked;
var y = document.getElementById("check").rows[i].cells;
id[i]=y[0].innerHTML;
}
}
</script>
</head>
<body>
<table id="check" >
<tr>
<th>S.No</th>
<th>Name</th>
<th>Age</th>
<th>Qualification</th>
<th> <input type="checkbox" onclick='checkedAll()'/> </th>
</tr>
<?php
$check=0;
$flag=0;
$my_checkbox=array();
foreach($forms as $ft): ?>
<tr id="<?php echo $check;?>" class="<?php echo $d ?>">
<td > <?php echo $ft['serial']; ?> </td>
<td> <?php echo $ft['name'] ;?></td>
<td> <?php echo $ft['age'] ;?></td>
<td> <?php echo $ft['qualification'] ;?></td>
<td> <input type="checkbox" /></td>
</tr>
<?php $check++ ?>
<?php endforeach ?>
<tr>
<td colspan="5" align="center">
<button type="button" name="create" id='but' value="Create"
onclick = "Redirect();" >Create </button>
<button type="button" name="edit" onclick="edit();" id='but' >Edit </button>
<button type="button" name="delete" id='but' onclick="del(); " >Delete </button>
</td>
</tr>
</table>
<form action="<?php $this->load->helper('url');echo site_url('form/edit');?>" method="POST" id="myForm" >
<input type="hidden" name="snap" id="snap">
</form>
</body>