发布未选中的复选框 [英] Post the checkboxes that are unchecked

查看:115
本文介绍了发布未选中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个默认选中的加载复选框。我的用户可能取消选中一些复选框(如果有),并选中其余的复选框。

I've got a load of checkboxes that are by default checked. My users will probably uncheck a few of the checkboxes (if any) and leave the rest of them checked. Is there any way to get the checkboxes that are NOT checked in a form post, rather than the ones that are checked?

推荐答案

有没有办法得到未在表单帖子中选中的复选框,为不同ID的复选框添加隐藏输入:

Add a hidden input for the checkbox with a different ID:

<input id='testName' type='checkbox' value='Yes' name='testName'>
<input id='testNameHidden' type='hidden' value='No' name='testName'>

在提交表单之前,请根据选中的条件禁用隐藏输入:

Before submitting the form, disable the hidden input based on the checked condition:

if(document.getElementById("testName").checked) {
    document.getElementById('testNameHidden').disabled = true;
}

这篇关于发布未选中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆