javascript - how to get data of checked multiple check boxes into js using onclick in php -


here code need fix

here ad_q_type field name of db , ad_q_ans_options field of db contains answers in concatenated comma

if($questions['ad_q_type'] == 1 && strpos($questions['ad_q_ans_options'],',') == true)         {              if($questions['ad_q_option1'] != "")              {                  echo '<input type="checkbox"  id="cleponlineexam_check1_'.$current_qno.'" class="css-checkbox lrg" name="op[]" value="1" onclick="toggle(this.id,1)"; />';                  echo '<label for="cleponlineexam_check1_'.$current_qno.'" name="checkbox67_lbl" class="css-label lrg web-two-style">[a] '.$questions['ad_q_option1'].'</label>';                  echo '<div class="clear"></div>';             }             if($questions['ad_q_option2'] != "")              {                 echo '<input type="checkbox" id="cleponlineexam_check2_'.$current_qno.'" class="css-checkbox lrg" name="op[]" value="2" onclick="toggle(this.id,2);" />';                 echo '<label for="cleponlineexam_check2_'.$current_qno.'" name="checkbox67_lbl" class="css-label lrg web-two-style">[b] '.$questions['ad_q_option2'].'</label>';                 echo '<div class="clear"></div>';             }             if($questions['ad_q_option3'] != "")             {                 echo '<input type="checkbox" id="cleponlineexam_check3_'.$current_qno.'" class="css-checkbox lrg" name="op[]" value="3" onclick="toggle(this.id,3);" />';                 echo '<label for="cleponlineexam_check3_'.$current_qno.'" name="checkbox67_lbl" class="css-label lrg web-two-style">[c] '.$questions['ad_q_option3'].'</label>';                 echo '<div class="clear"></div>';             }              if($questions['ad_q_option4'] != "")             {                 echo '<input type="checkbox" id="cleponlineexam_check4_'.$current_qno.'" class="css-checkbox lrg" name="op[]" value="4" onclick="toggle(this.id,4);" />';                 echo '<label for="cleponlineexam_check4_'.$current_qno.'" name="checkbox67_lbl" class="css-label lrg web-two-style">[d] '.$questions['ad_q_option4'].'</label>';                 echo '<div class="clear"></div>';             }             if($questions['ad_q_option5'] != "")             {                 echo '<input type="checkbox" id="cleponlineexam_check5_'.$current_qno.'" class="css-checkbox lrg" name="op[]" value="5" onclick="toggle(this.id,5);" />';                 echo '<label for="cleponlineexam_check5_'.$current_qno.'" name="checkbox67_lbl" class="css-label lrg web-two-style">[e] '.$questions['ad_q_option5'].'</label>';                 echo '<div class="clear"></div>';             }                    if($questions['ad_q_option6'] != "")             {                 echo '<input type="checkbox" id="cleponlineexam_check6_'.$current_qno.'" class="css-checkbox lrg" name="op[]" value="6"  onclick="toggle(this.id,6);" />';                 echo '<label for="cleponlineexam_check6_'.$current_qno.'" name="checkbox67_lbl" class="css-label lrg web-two-style">[f] '.$questions['ad_q_option6'].'</label>';                 echo '<div class="clear"></div>';             }              if($questions['ad_q_option7'] != "")             {                 echo '<input type="checkbox" id="cleponlineexam_check7_'.$current_qno.'" class="css-checkbox lrg" name="op[]" value="7" onclick="toggle(this.id,7);" />';                 echo '<label for="cleponlineexam_check7_'.$current_qno.'" name="checkbox67_lbl" class="css-label lrg web-two-style">[g] '.$questions['ad_q_option7'].'</label>';                 echo '<div class="clear"></div>';             }             if($questions['ad_q_option8'] != "")              {                 echo '<input type="checkbox" id="cleponlineexam_check8_'.$current_qno.'" class="css-checkbox lrg" name="op[]" value="8"  onclick="toggle(this.id,8);"  />';                 echo '<label for="cleponlineexam_check8_'.$current_qno.'" name="checkbox67_lbl" class="css-label lrg web-two-style">[h] '.$questions['ad_q_option8'].'</label>';                  echo '<div class="clear"></div>';             }             if($questions['ad_q_option9'] != "")             {                 echo '<input type="checkbox" id="cleponlineexam_check9_'.$current_qno.'" class="css-checkbox lrg" name="op[]" value="9" onclick="toggle(this.id,9);"  />';                 echo '<label for="cleponlineexam_check9_'.$current_qno.'" name="checkbox67_lbl" class="css-label lrg web-two-style">[i] '.$questions['ad_q_option9'].'</label>';                 echo '<div class="clear"></div>';             }                } 

and here toggle function of js called after every click on checkbox

    function toggle(ctrlid, optionno) {         //alert(ctrlid + ' ' + optionno);         var allans = document.getelementbyid('clep_answers').value;         //alert(allans);         var queno = document.getelementbyid(ctrlid.replace('check1', 'qno')).innerhtml;          if (queno == '')             queno = document.getelementbyid(ctrlid.replace('check2', 'qno')).innerhtml;         if (queno == '')             queno = document.getelementbyid(ctrlid.replace('check3', 'qno')).innerhtml;         if (queno == '')             queno = document.getelementbyid(ctrlid.replace('check4', 'qno')).innerhtml;         if (queno == '')             queno = document.getelementbyid(ctrlid.replace('check5', 'qno')).innerhtml;         if (queno == '')             queno = document.getelementbyid(ctrlid.replace('check6', 'qno')).innerhtml;         if (queno == '')             queno = document.getelementbyid(ctrlid.replace('check7', 'qno')).innerhtml;         if (queno == '')             queno = document.getelementbyid(ctrlid.replace('check8', 'qno')).innerhtml;         if (queno == '')             queno = document.getelementbyid(ctrlid.replace('check9', 'qno')).innerhtml;              } 

my problem is working single click option when coming multiple clicking not working mean concatenating not done in 1 me fix issue


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -