【发布时间】:2011-11-04 21:16:36
【问题描述】:
我已经到处寻找答案,希望这里有人可以提供帮助。当您从一组复选框中选中一个复选框时,我有一个脚本会运行。复选框被分配一个值“客户ID”
<input type="checkbox" name="inv_add[]" onclick="setcid(\''.$result['cid'].'\')" value='.$result['id'].'/>
javascript 的重点是为隐藏字段分配一个值,告诉下一页所有复选框的客户 ID 是什么。
如果您的用户选中了一个分配给不同客户的框(因此不属于该组),我想提醒用户,然后取消选中最后一个选中的框。 我可以一直到警报,但不能取消选中用户刚刚选中的框。
function setcid(cid) {
if (window.set_x === undefined) {
sethidden = document.getElementById('cid');
sethidden.value = cid;
set_x = cid;
alert ("finished setting x");
}
else if (cid !== set_x){
alert ("You are trying to add two different companies to the same invoice");
/*Uncheck the box just checked by user*/
}
else {
alert("they are the same");
/*no modification required*/
}
}
【问题讨论】:
标签: javascript function checkbox