我有桌子和复选框(能够检查),我如何将复选框中的值传递给另一个页面?我应该编写javascript函数还是使用PHP来获得更好的解决方案。例如,选中复选框时,传递复选框值,如果未选中则传递0
这是我的表:
<table border="1">
<thead>
<tr>
<th><input type="checkbox" id="chkAll" onclick="allChecked(this.checked);"/></th>
<th>Invoice No.</th>
<th>Invoice Date</th>
<th>Due Date</th>
<th>Invoice Amount</th>
<th>Open Amount</th>
</tr>
</thead>
<form id="frmPaySelected">
<tbody>
<tr>
<td><input type="checkbox" name="invoice_no[]" value="IN000001" onclick="addTotal(this.checked, 1500.00);"/></td>
<td>IN000001</td>
<td align="right">11 Jan, 2018</td>
<td align="right">10 Feb, 2018</td>
<td align="right">1,500.00</td>
<td align="right">1,500.00</td>
</tr>
<tr>
<td><input type="checkbox" name="invoice_no[]" value="IN000003" onclick="addTotal(this.checked, 1500.00);"/></td>
<td>IN000003</td>
<td align="right">16 Jan, 2018</td>
<td align="right">15 Feb, 2018</td>
<td align="right">2,150.00</td>
<td align="right">1,500.00</td>
</tr>
<tr>
<td><input type="checkbox" name="invoice_no[]" value="IN000004" onclick="addTotal(this.checked, 259.50);"/></td>
<td>IN000004</td>
<td align="right">30 Jan, 2018</td>
<td align="right">31 Mar, 2018</td>
<td align="right">900.00</td>
<td align="right">259.50</td>
</tr>
<tr>
<td colspan="4" align="right"><strong>Total: </strong></td>
<td><div style="text-align:right; font-weight:bold;">5,538.25</div></td>
<td><div id="divTotalPayAmount" style="text-align:right; font-weight:bold;">0.00</div></td>
</tr>
<tr>
<td colspan="6" align="right"><input type="button" value="Pay Selected" onclick="alert('Submit Selected!');"/></td>
</tr>
</tbody>
</form>
</table>
“javascript checkbox function”
<script language="JavaScript">
var totalOpenAmount = 0;
var blnUpdateCheckAll = true;
function allChecked(checkValue) {
var chkInvoices = document.getElementsByName('invoice_no[]');
blnUpdateCheckAll = false;
for(i = 0; i < chkInvoices.length; i++) {
if(chkInvoices[i].checked != checkValue)
chkInvoices[i].click();
}
blnUpdateCheckAll = true;
}
function updateAllChecked() {
var chkInvoices = document.getElementsByName('invoice_no[]');
var c = 0;
for(i = 0; i < chkInvoices.length; i++) {
if(chkInvoices[i].checked)
c++;
}
if(c < i)
document.getElementById('chkAll').checked = false;
else
document.getElementById('chkAll').checked = true;
}
function addTotal(checkValue, openAmount) {
if(checkValue)
totalOpenAmount += openAmount;
else
totalOpenAmount -= openAmount;
if(blnUpdateCheckAll) updateAllChecked();
document.getElementById('divTotalPayAmount').innerHTML = totalOpenAmount.toFixed(2).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
}
</script>