Hi there,
I am having some difficulty as to writing the code for a group of checkboxes in array.
In a group of Five checkboxes, if the first one is checked than the rest 4 check boxes gets disabled. Right now the code is working when I am using document.form.elementname.disabled=true. But it does not work when i use getElementByID since the group has the same id (e.g. id= 'q2_1_1[]').
I am using the id in array so that i can save multiple values in 1 field in MySQL. Other alternatives will be welcome too.
How do i call the function to disable and enable using the getElementById and this array?
I have something similar for multiple listbox where i am using array. If I know this one probably i'll be able to apply to the listbox as well. Below is the code.
Thanks in advance for your help.
HTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <script type="text/javascript"> function makeChoice() { if(document.comparison_group.q_2_1_1_1.checked == true) { document.comparison_group.q_2_1_1_2.disabled=true; document.comparison_group.q_2_1_1_2.checked=false; document.comparison_group.q_2_1_1_3.disabled=true; document.comparison_group.q_2_1_1_3.checked=false; document.comparison_group.q_2_1_1_4.disabled=true; document.comparison_group.q_2_1_1_4.checked=false; document.comparison_group.q_2_1_1_5.disabled=true; document.comparison_group.q_2_1_1_5.checked=false; /* the code in the next line does not work when i try the array document.getElementById('q_2_1_1'[1]).disabled=true;*/ } else { document.comparison_group.q_2_1_1_2.disabled=false; document.comparison_group.q_2_1_1_3.disabled=false; document.comparison_group.q_2_1_1_4.disabled=false; document.comparison_group.q_2_1_1_5.disabled=false; } } </script> <title></title> </head> <body> <form name='comparison_group' method='post' > <table style='width:500px; border:1px solid green'> <tr> <td style='width:200px; text-align:right;'> <label> No Comparison Group </label> </td> <td style='width:20px;'> <input id='q_2_1_1[]' name='q_2_1_1_1' type='checkbox' onclick='makeChoice();' value='0' /> </td> <td> </td> </tr> <tr> <td style='text-align:right;'> <label> Normative sample (please specify)</label> </td> <td> <input id='q_2_1_1[]' name='q_2_1_1_2' type='checkbox' value='1' /> </td> <td> </td> </tr> <tr> <td style='text-align:right;'> <label> Comparison with Condition (please specify)</label> </td> <td> <input id='q_2_1_1[]' name='q_2_1_1_3' type='checkbox' value='2' /> </td> <td> </td> </tr> <tr> <td style='text-align:right;'> <label> Comparison with No Condition (please specify)</label> </td> <td> <input id='q_2_1_1[]' name='q_2_1_1_4' type='checkbox' value='3' /> </td> <td> </td> </tr> <tr> <td style='text-align:right;'> <label> Within Group Analysis (please specify)</label> </td> <td> <input id='q_2_1_1[]' name='q_2_1_1_5' type='checkbox' value='4' /> </td> <td> </td> </tr> </table> <table> <tr> <td > <p style="text-align:left;">What is the sampling procedure for the observational group?</p> </td> <td > <select id="q_2_2_1[]" name="q_2_2_1_1" size='7' multiple style="width:150px;"> <option value='0'>Random</option> <option value='1'>Convenience</option> <option value='2'>Purposive</option> <option value='3'>Quota</option> <option value='4'>Subsample from other study</option> <option value='5'>Other</option> <option value='8'>Unclear</option> </select> <?php @$procedure= $_POST['procedure']; if( is_array($procedure)){ while (list ($key, $val) = each ($procedure)) { echo $val.", "; } }//else{echo "not array";} ?> </td> <td width='200px;'> </td> </tr> </table> </form> </body> </html>



Reply With Quote
Bookmarks