简体   繁体   中英

Javascript Checkbox Validation stuck with Value of multiple checkbox

I have an problem with my checkbox submit. I know when we want to submit multiple value checkbox we must put inside name like : ccd_pos[]. But now its not function, because I have an javascript validation that the function is enabled checkbox 2,3,4 after checkbox 1 checked. You can see my code so far below :

Javascript Code

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 checkbox

<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

So now my question is how to make the checkbox keep function and value of checkbox can be combine when I submit that.

Thanks.

You need to use Jquery to run the document..... here is the code.. I have made some changes....

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

Front Back 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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