삭제한 요소가 onsubmit에서 form 확인 시 갯수로 카운팅되고 있어요

삭제한 요소가 onsubmit에서 form 확인 시 갯수로 카운팅되고 있어요

QA

삭제한 요소가 onsubmit에서 form 확인 시 갯수로 카운팅되고 있어요

본문



<span>
  <select name="wr_situation" class="wr_situation">
    <option value="enteringHome">홈 화면 진입 시 띄움</option>
    <option value="completePayment">결제완료 후 띄움</option>
    <option value="completeAttendance">입장완료 후 띄움</option>
  </select><a href="#" class="remove_btn"><img src="<?= G5_URL ?>/img/remove-icon.png"/></a>
</span>

 

이 span 요소를 지우는것은 remove_btn 클릭시 아래 코드를 통해 지웠습니다.



$('a.remove_btn').on('click', function(e) {
  e.preventDefault();
  // Remove the parent span element when the button is clicked
  $(this).parent('span').remove();
});

 

그후 해당 form을 submit 할때 onsubmit="f_onsubmit(this)" 

function f_onsubmit (f) {

console.log(f.wr_situation.length)

}

갯수가 삭제 이전과 카운팅이 같습니다.

 

대신 추가 시에는 잘 적용된걸 확인했습니다.

 

삭제 후 갯수가 맞도록 하려면 어떻게 해야하나요?

 

이 질문에 댓글 쓰기 :

답변 1

삭제 후 갯수를 업데이트 하려면 아래와 같이 하면 됩니다.



$('a.remove_btn').on('click', function(e) {
  e.preventDefault();
  // Remove the parent span element when the button is clicked
  $(this).parent('span').remove();
  // Update the length of the wr_situation element
  f.wr_situation.length = f.wr_situation.length - 1;
});

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

회원로그인

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