나의 성장과정  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
코드

상황 : txtArray란 이름을 가진 input Object가 0개 이상 발생한다.

<%
 for(int i=0; i<bean.size(); i++)
{
%>
 <input name="txtArray" value="<%= bean.getID() %>" />
<%         
}   
%>

경우의수1 : txtArray 가 아예 없는경우 ( 이런 경우 액션이 일어나지않도록 화면에서 처리한다.)
경우의수2 : txtArray가 한개 있는경우
경우의수3 : txtArray가 두개 이상인경우

문제발생
javascript로 txtArray의 값을 검증할때, 경우의 수에 따라
처리가 달라지기 때문에
코드가 2배로늘어나고 관리가 힘들다.

내가 해왔던 코드 vs 대안 코드
ex)    

function foo(){
           var test = document.frm.txtArray;
         
            if(test.length > 1 ){
              for(var i = 0 ; i<test.length; i++) {
                if(test[i].value == "") {
                    alert("값을 입력 하세요");
                }
              }
            }else {
                if(test.value == "") {
                    alert("값을 입력 하세요");
                }
            }
        }

      

function foo()
       {
              var oFields = document.getElementsByName("txtArray");
              var nLoop;
             
              for( nLoop = 0 ; nLoop < oFields.length ; nLoop++ )
              {    
                    if( oFields[nLoop].value == "" )
                    {
                      alert("값을 입력 하세요");
                      return;
                    }
              }
       }

좀더 고급의 javascript를알고 싶다.


BLOG main image
Simple is beatiful!
 Notice
 Category
분류 전체보기 (755)
전직 (0)
일상 (7)
진행중 (6)
3Fs (14)
미정 (3)
Serendipitous! (6)
지르자 : 맥북 (5)
(5)
FaceBook (3)
 TAGS
Java primitive URL URLConnection Debug DOM 커피 Safari JS JavaScript Eclipse color tomcat 자바스크립트 laserjet HP 네트워크 CP1215 접근지정자 사파리
 Calendar
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
 Recent Entries
 Recent Comments
 Archive
 Link Site
상상할 수 있는 힘이 ..
즐겁게살자
인생의 소중한 꿈
{fly to the ocean.com}
누노의 컴퓨토피아
한RSS
[지인]I can\'t stop. Love. Lo…
[원츄]OK 괜찮아 다 잘 될거야
[원츄]애자일 이야기
[원츄]IBM Developerworks
 Visitor Statistics
Total :
Today :
Yesterday :
rss