자바스크립트 배열값(?) 질문 있습니다

자바스크립트 배열값(?) 질문 있습니다

QA

자바스크립트 배열값(?) 질문 있습니다

본문

아래를 보시면, 보기를 클릭하면,

form의 보기의 wr_id의 value 값을,

그 아래 자바스크립트에서  받아서 wr_8에 등록된 정답과 비교해서

일치하면, 해설 wr_12를 담고 있는 div를 펼치고,

오답이면 오답 div를 펼치는 소스인데요.

 

문제점은, 오로지 한 문제 있을때만 작동하고,

문제거 2개 이상 등록되면, 개별적 배열값 문제인지

그나마 혼자 있을때 된던 문제마저 전혀 작동하지 않습니다.

 

해결책 부탁드립니다. ^^

 


 <?php
 for ($i=0; $i < $list_cnt; $i++) {
 
       <?php if ($is_checkbox) { ?>
       <input type="checkbox" name="chk_wr_id[]" value="<?php echo $list[$i]['wr_id'] ?>" id="chk_wr_id_<?php echo $i ?>">
       <?php } ?>

       <?php if ($list[$i]['wr_1']) { ?>
       <i class="fa" style="float:left; font-size:14px; font-family:'adbfont'; color:#fff; border:0px solid #aaa; border-radius:5%; height:35px; min-width:35px; text-align:center; padding-top:5px;line-height:250%;background:url('<?php echo $serial_skin_url?>/img/black-35-trans.png') repeat;"><?php echo $list[$i]['wr_9'] ?></i>
       <?php } ?>
 
  <?php if( $list[$i]['wr_3']) { ?>
   <form name="form">
   <div class="form-group">
    <div class="mid">
     <div class="input-group input-group-sm" style="float:left;margin-bottom:10px;">
     <input onclick="myFucntion();" type=radio name="wr_id" id="wr_3" value="1"><label for="wr_3"><span><?php echo $list[$i]['wr_3'] ?></span></label>
     </div>
     <div class="input-group input-group-sm" style="float:left;margin-bottom:10px;">
     <input onclick="myFucntion();" type=radio name="wr_id" id="wr_4" value="2"><label for="wr_4"><span><?php echo $list[$i]['wr_4'] ?></span></label>
     </div>
     <div class="input-group input-group-sm" style="float:left;margin-bottom:10px;">
     <input onclick="myFucntion();" type=radio name="wr_id" id="wr_5" value="3"><label for="wr_5"><span><?php echo $list[$i]['wr_5'] ?></span></label>
     </div>
     <?php if( $list[$i]['wr_6']) { ?>
     <div class="input-group input-group-sm" style="float:left;margin-bottom:10px;">
     <input onclick="myFucntion();" type=radio name="wr_id" id="wr_6" value="4"><label for="wr_6"><span><?php echo $list[$i]['wr_6'] ?></span></label>
     </div>
     <?php } ?>
     <?php if( $list[$i]['wr_7']) { ?>
     <div class="input-group input-group-sm" style="float:left;margin-bottom:10px;">
     <input onclick="myFucntion();" type=radio name="wr_id" id="wr_7" value="5"><label for="wr_7"><span><?php echo $list[$i]['wr_7'] ?></span></label>
     </div>
     <?php } ?>
    </div>
   </div>
  </form>
  <div style="clear:both;height:10px;"></div>
  <p class="check" id="check"></p>
   <script type="text/javascript">
    function myFucntion() {
      if(form.wr_id[<?php echo $list[$i]['wr_8'] -1 ?>].checked==true) document.getElementById("check").innerHTML="<div class='view-mine' style='width:100%;color:#444;padding:15px 20px 20px 20px; font-size: 16px; font-family:Malgun Gothic,Verdana; line-height:190%; margin:0;border:1px solid #ddd;font-weight:400;color:#555;'><table width=100% style='background:url(<?=$serial_skin_url ?>/img/answer_s_oo.png) no-repeat;background-size:contain;background-position:top center;min-height:198px;'><tr><td valign='top' style='word-break:keep-all;white-space:pre-line;'><?=$list[$i]['wr_12']?></td></tr></table></div><div style='clear: both;'></div>";
      else document.getElementById("check").innerHTML="<div class='view-mine' style='color:#444;padding:15px 20px 20px 20px; font-size: 13px; font-family:Malgun Gothic,Verdana; line-height:190%; margin:0;border:1px solid #ddd;font-weight:500;'><img src='<?=$serial_skin_url ?>/img/answer_s_xx.png' alt='오답' class='cursor at-tip' data-original-title='오답' data-toggle='tooltip'></div>";
      }
   </script>
  <?php } ?>
 
 
 
 <?php } ?>
 

 

**************** 참고 ****************

한 문제 있을때, 정상작동하는 예를 첨부이미지에 올립니다.

 

661840930_1550386227.0784.gif661840930_1550386232.9572.gif

이 질문에 댓글 쓰기 :

답변 3

myFucntion() 소스가 문제의 정답을 체크하는 소스인것 같은데 관련부분은 올라와있지 않네요.

정확히는 알 수 없습니다만

문제가 여러개인 경우 동작 안하는 이유는 input name값이 중복되어서라고 보여집니다.

소스는 저게 다예요.

if(form.wr_id[<?php echo $list[$i]['wr_8'] -1 ?>].checked==true)

이부분이 정답체크 부분입니다.

 

볼피드님 말씀대로  input name 개별적(?)으로 주어져야 할 것 같은데,

잘 몰라서요.

좀 더 구체적으로 부탁드립니다. ^^

 

Uncaught TypeError: Cannot read property '2' of undefined
    at myFucntion (board.php?bo_table=ebook&wr_id=1:3240)
    at HTMLInputElement.onclick (board.php?bo_table=ebook&wr_id=1:1341)
이런 오류가 뜨고 있네요.

츌력되는 페이지를  소스보기 해보세요

form name중복 , myFucntion()도 중복 

저렇게 되어서는 당연히 에러납니다

스타일 코드도 class로 만들고 전체 코드를 다시 만들어야겠습니다

Q/A로는 어렵겠습니다

답변을 작성하시기 전에 로그인 해주세요.
전체 818
QA 내용 검색
filter #DB ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT