簡體   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