같은 name의 select가 여러개일때 질문드립니다.

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
같은 name의 select가 여러개일때 질문드립니다.

QA

같은 name의 select가 여러개일때 질문드립니다.

본문

같은 name의 select box가 5개 정도 있습니다.

처음 1번 select 를 선택 > 정상

수정에서 2번 select 선택  > 정상

다시 수정에서 2번을 제외 다른 select 선택 > 안나옴 또는 2번 값 고정

 

이런 현상이 반복되는데 

select는 같은 name을 사용할 수 없는걸까요? 

 

 

 

<select name="wr_1" style="<?if($write[ca_name]== "1"){?>display: inline-block;<?}else{?>display: none;<?}?>">

<option value="" selected>2차 분류 선택</option>

<option value="11" <? if($write[wr_1] == '11'){?>selected<?}?>>11</option>

<option value="12" <? if($write[wr_1] == '2212){?>selected<?}?>>12</option>

<option value="13" <? if($write[wr_1] == '13'){?>selected<?}?>>13</option>

<option value="14" <? if($write[wr_1] == '14'){?>selected<?}?>>14</option>

</select>

<select name="wr_1"style="<?if($write[ca_name]== "2"){?>display: inline-block;<?}else{?>display: none;<?}?>">

<option value="" selected>2차 분류 선택</option>

<option class="21" <? if($write[wr_1] == '21'){?>selected<?}?>>21</option>

<option class="22" <? if($write[wr_1] == '22'){?>selected<?}?>>22</option>

<option class="23" <? if($write[wr_1] == '23'){?>selected<?}?>>23</option>

<option class="24" <? if($write[wr_1] == '24'){?>selected<?}?>>24</option>

<option class="25" <? if($write[wr_1] == '25'){?>selected<?}?>>25</option>

</select>

<select name="wr_1" style="<?if($write[ca_name]== "3"){?>display: inline-block;<?}else{?>display: none;<?}?>">

<option value="" selected>2차 분류 선택</option>

<option class="31" <? if($write[wr_1] == '31'){?>selected<?}?>>31</option>

<option class="32" <? if($write[wr_1] == '32'){?>selected<?}?>>32</option>

<option class="33" <? if($write[wr_1] == '33'){?>selected<?}?>>33</option>

<option class="34" <? if($write[wr_1] == '34'){?>selected<?}?>>34</option>

<option class="35" <? if($write[wr_1] == '35'){?>selected<?}?>>35</option>

</select>

이 질문에 댓글 쓰기 :

답변 3

css(display:none)으로 가림쳐리한다고해서 해당 select박스가 사라지는게아니에요.

값은그대로전송되기떄문에

 

display:none말고

 

<?if($write[ca_name]== "1"){?>

<select name="wr_1">

<option value="" selected>2차 분류 선택</option>

<option value="11" <? if($write[wr_1] == '11'){?>selected<?}?>>11</option>

<option value="12" <? if($write[wr_1] == '2212){?>selected<?}?>>12</option>

<option value="13" <? if($write[wr_1] == '13'){?>selected<?}?>>13</option>

<option value="14" <? if($write[wr_1] == '14'){?>selected<?}?>>14</option>

</select>

<?php }elseif($write[ca_name]== "2"){

<select name="wr_1">

<option value="" selected>2차 분류 선택</option>

<option class="21" <? if($write[wr_1] == '21'){?>selected<?}?>>21</option>

<option class="22" <? if($write[wr_1] == '22'){?>selected<?}?>>22</option>

<option class="23" <? if($write[wr_1] == '23'){?>selected<?}?>>23</option>

<option class="24" <? if($write[wr_1] == '24'){?>selected<?}?>>24</option>

<option class="25" <? if($write[wr_1] == '25'){?>selected<?}?>>25</option>

</select>

<? }else{ ?>

<select name="wr_1">

<option value="" selected>2차 분류 선택</option>

<option class="31" <? if($write[wr_1] == '31'){?>selected<?}?>>31</option>

<option class="32" <? if($write[wr_1] == '32'){?>selected<?}?>>32</option>

<option class="33" <? if($write[wr_1] == '33'){?>selected<?}?>>33</option>

<option class="34" <? if($write[wr_1] == '34'){?>selected<?}?>>34</option>

<option class="35" <? if($write[wr_1] == '35'){?>selected<?}?>>35</option>

</select>

<?php } ?>

 

이렇게해보세요.

감사합니다. :)
값은 잘 들어가는데,  1차분류인  ca_name을 클릭하면 2차분류가 나와야하는데
위처럼 하니 2차분류가 나오질 않는데 방법이 있을까요..? ㅠ

같은 네임명을 사용하는 태그를 한 페이지에 사용할 수 없습니다
HTML 자체가 엄격하지 않고 에러 출력이 없기 때문에 그냥 보여지고 수행되는것일뿐입니다
해당 영역에 있는 값을 동일한 값으로 합치고 싶다면 폼 전송 이벤트에서 자바크스크립트로 하나의 필드로 몰아넣거나 하셔야 합니다

조건문으로 해도 select가 복수로 생성되어야 한다면 아래와 같이 시도해 봐도 될 듯: jquery에서 class 명 이용

...

<input type="hidden" name="wr_1" id="wr_1">

 

<?php

for ($i=1;$i<=3;$i++) {

  if ($write['ca_name'] == $i) {

    <select name="select_<?php echo $i?>" id="select_<?php echo $i?>" class="class_select">

      <option value="">2차 분류 선택</option>

      <?php

          $str_selected = "";

          for ($j=1;$j<=5;$j++) {

            if ($write['wr_1'] == $i.$j) $str_selected = "selected"; ?>

           <option  value = '<?php echo $i.$j;?>' <?php echo  $str_selected; ?>><?php echo $i.$j;?></option>

      <?php  } ?>

      </select>

 

<script>

$('.class_select').on('change', function() {
        $('#wr_1').val($('#select_<?php echo $i?>').val());
});

</script>

<?php }

 } ?>

 

 

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

회원로그인

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