Home:ALL Converter>Javascript Checkbox Validation stuck with Value of multiple checkbox

Javascript Checkbox Validation stuck with Value of multiple checkbox

Ask Time:2013-05-25T12:43:47         Author:Interval Grid

Json Formatter

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.

Author:Interval Grid,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/16746490/javascript-checkbox-validation-stuck-with-value-of-multiple-checkbox
sanj :

You need to use Jquery to run the document.....\nhere is the code.. I have made some changes....\n\n <script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js\"></script>\n<script type=\"text/javascript\">\n $(document).ready(function(){\n$('#ccd_chk').click(function(){\n if (theForm.ccd_chk.checked)\n {\n theForm.ccd_pos [0].disabled = false;\n theForm.ccd_pos [0].checked = false;\n theForm.ccd_pos [1].disabled = false;\n theForm.ccd_pos [1].checked = false;\n theForm.ccd_pos [2].disabled = false;\n theForm.ccd_pos [2].checked = false;\n } else {\n theForm.ccd_pos [0].disabled = true;\n theForm.ccd_pos [1].disabled = true;\n theForm.ccd_pos [2].disabled = true;\n }\n});\n});\n</script>\n\n\n\n\n\n \n \n Front\n Back\n FB\n \n \n ",
2013-05-25T05:06:36
yy