繁体   English   中英

Javascript复选框验证卡在“多个”复选框中

[英]Javascript Checkbox Validation stuck with Value of multiple checkbox

我的复选框提交有问题。 我知道当我们要提交多个值复选框时,我们必须在名称内输入:ccd_pos []。 但现在它不起作用了,因为我对第一个复选框1进行了检查后,通过JavaScript验证了该功能已启用,第2、3、4个复选框。 您可以在下面看到我的代码:

JavaScript代码

if (theForm.ccd_chk.checked)
{
    theForm.ccd_pos [0].className = 'part';
    theForm.ccd_pos [1].className = 'part';
    theForm.ccd_pos [2].className = 'part';

    theForm.ccd_pos [0].disabled  = false;
    theForm.ccd_pos [0].checked  = false;
    theForm.ccd_pos [1].disabled  = false;
    theForm.ccd_pos [1].checked  = false;
    theForm.ccd_pos [2].disabled  = false;
    theForm.ccd_pos [2].checked  = false;
}
else
{
    theForm.ccd_pos [0].disabled  = true;
    theForm.ccd_pos [1].disabled  = true;
    theForm.ccd_pos [2].disabled  = true;
}

HTML复选框

<input type="checkbox" name="ccd_chk" value="yes" class="part" onclick="ActionCcdCheck (this.form);" onkeypress="FocusChange (this.form, 5, 4);"/>
<input type="checkbox" name="ccd_pos" value="front" class="part" onkeypress="FocusChange (this.form, 6, 3);"/> Front
<input type="checkbox" name="ccd_pos" value="back" class="part" onkeypress="FocusChange (this.form, 7, 2);"/> Back
<input type="checkbox" name="ccd_pos" value="fb" class="part" onkeypress="FocusChange (this.form, 8, 1);"/> FB

所以现在我的问题是如何在提交时使复选框保持功能和复选框的值能够结合在一起。

谢谢。

您需要使用Jquery来运行文档.....这是代码..我进行了一些更改....

 <script type="text/javascript"        src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
$('#ccd_chk').click(function(){
    if (theForm.ccd_chk.checked)
    {
        theForm.ccd_pos [0].disabled  = false;
        theForm.ccd_pos [0].checked  = false;
        theForm.ccd_pos [1].disabled  = false;
        theForm.ccd_pos [1].checked  = false;
        theForm.ccd_pos [2].disabled  = false;
        theForm.ccd_pos [2].checked  = false;
    } else {
        theForm.ccd_pos [0].disabled  = true;
        theForm.ccd_pos [1].disabled  = true;
        theForm.ccd_pos [2].disabled  = true;
    }
});
});
</script>

前后FB

Hers is the HTML part.....   
 <body>
 <form id="theForm" name="theForm">
 <input type="checkbox" name="ccd_chk" value="yes" onclick="ActionCcdCheck (this.form);"        onkeypress="FocusChange (this.form, 5, 4);" id="ccd_chk"/>
  <input type="checkbox" name="ccd_pos" value="front" onkeypress="FocusChange (this.form, 6, 3);" disabled="disabled"/> Front
 <input type="checkbox" name="ccd_pos" value="back" onkeypress="FocusChange (this.form, 7,   2);" disabled="disabled"/> Back
 <input type="checkbox" name="ccd_pos" value="fb" onkeypress="FocusChange (this.form, 8, 1);" disabled="disabled"/> FB
</form>
</body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM