질문

javascript , recordset 검색 출력 내공5

qowlssla
2007.06.16 03:04
답변
1
조회
1,030

- xml 문서 -

<?xml version="1.0" encoding="euc-kr"?>
<시간표>
 <과목>
   <과목명>디지털</과목명>
   <분반>01</분반>
   <교수>김정호</교수>
   <학점>3</학점>
   <학년>1</학년>
   <강의시간>수</강의시간>
 </과목>
 <과목>
   <과목명>디지털</과목명>
   <분반>02</분반>
   <교수>김정호</교수>
   <학점>3</학점>
   <학년>1</학년>
   <강의시간>월</강의시간>
 </과목>
 <과목>
   <과목명>컴퓨터개론</과목명>
   <분반>01</분반>
   <교수>장경</교수>
   <학점>3</학점>
   <학년>1</학년>
   <강의시간>월</강의시간>
 </과목>
 <과목>
   <과목명>프로그래밍</과목명>
   <분반>01</분반>
   <교수>김재호</교수>
   <학점>3</학점>
   <학년>1</학년>
   <강의시간>화</강의시간>
 </과목>
 <과목>
   <과목명>프로그래밍</과목명>
   <분반>02</분반>
   <교수>김재호</교수>
   <학점>3</학점>
   <학년>1</학년>
   <강의시간>화</강의시간>
 </과목>
 <과목>
   <과목명>기초java</과목명>
   <분반>01</분반>
   <교수>경현수</교수>
   <학점>3</학점>
   <학년>1</학년>
   <강의시간>목</강의시간>
 </과목>
 <과목>
   <과목명>기초java</과목명>
   <분반>02</분반>
   <교수>경현수</교수>
   <학점>3</학점>
   <학년>1</학년>
   <강의시간>목</강의시간>
 </과목>
..........
</시간표>

 

-html문서-

<HTML>
 <HEAD>
   <TITLE>시간표 검색</TITLE>
 </HEAD>

 <BODY>
 <XML ID="IslandName" SRC="시간표.xml"></XML>
 <H3> 2007-1학기</H3>
 <H2>시간표 검색</H2>
  과목명 : <INPUT TYPE="TEXT" ID="SearchText">
  교수 : <INPUT TYPE="TEXT" ID="SearchText2">
 <BUTTON onCLICK='Find()'>  검색  </BUTTON>
 <BR/><BR/><HR>
  - 결 과 - <BR>
 <P>
 <DIV ID=ResultDiv></DIV>
 <SCRIPT LANGUAGE="JavaScript">
  function Find()
  {
 SearchString=SearchText.value.toUpperCase();
 SearchString2=SearchText2.value.toUpperCase();
 

 if (SearchString,SearchString2=="")
 {
  ResultDiv.innerHTML="검색어를 넣어주세요";
  return;
 }
 IslandName.recordset.moveFirst();
 ResultHTML="";
 ResultHTML2=""; 
 while (!IslandName.recordset.EOF)
 {
   TitleString=IslandName.recordset("과목명").value;
  TCString=IslandName.recordset("교수").value;

  if (TitleString.toUpperCase().indexOf(SearchString)>=0)
      ResultHTML+= IslandName.recordset("과목명")
          + " , "
          + IslandName.recordset("분반")
          + "반 , "
          + IslandName.recordset("교수")
          + "교수님 , "
          + IslandName.recordset("학점")
          + "학점 , "
          + IslandName.recordset("학년")
          + "학년 , "
          + IslandName.recordset("강의시간")
  

  if (TCString.toUpperCase().indexOf(SearchString2)>=0)
      ResultHTML2+= IslandName.recordset("과목명")
          + " , "
          + IslandName.recordset("분반")
          + "반 , "
          + IslandName.recordset("교수")
          + "교수님 , "
          + IslandName.recordset("학점")
          + "학점 , "
          + IslandName.recordset("학년")
          + "학년 , "
          + IslandName.recordset("강의시간")
          + "<BR>";
  IslandName.recordset.moveNext();


 }
 
 if (ResultHTML=="")
               ResultDiv.innerHTML="일치하는 정보가 없습니다";
 else
   ResultDiv.innerHTML=ResultHTML;

 if (ResultHTML2=="")
               ResultDiv.innerHTML="일치하는 정보가 없습니다";
 else
   ResultDiv.innerHTML=ResultHTML2;

  }

 </SCRIPT>

 </BODY>
</HTML>

// 검색을 두개칸으로 했는데요 , 한 칸만 키워드를 입력해도 출력하길 원하는데

과목명입력시엔 출력이 제대로 안되네요

뭐가 문제인지 모르겠어요 , 도와주세요 ^^

 

질문자 채택된 경우, 추가 답변 등록이 불가합니다.

질문자 채택

re: javascript , recordset 검색 출력

dmysonic
답변채택률 92.3%
2007.06.16 10:41

안녕하세요 ^^;

일단 안되는 이유부터 말씀드린다면 while문 안에서 과목명을 비교하고, 그레코드셋에 대하여 다시 강사명을 또 비교하기 때문이구요.

이럴 경우 과목명만 입력되었을 때, 강사명만 입력되었을 때 각각 구분해주어야 합니다.

수업시간에 몰래 답변드리느라 이거 원 덜덜덜

시간여유있으면 깔끔하게 고쳐드릴텐데 ㅎㅎㅎ

 

최대한 님의 소스를 그대로 이용해서 수정했으니 참고해보세요 ^^;

 

수정한 스크립트 소스는 첨부할께요.

원하시는 대로는 동작하기는 할꺼에요 ^^;

 

==========================================================================

 <script LANGUAGE="JavaScript">
  function Find()
  {
 SearchString=SearchText.value.toUpperCase();
 SearchString2=SearchText2.value.toUpperCase();

IslandName.recordset.moveFirst();
ResultHTML="";

if (SearchString=="" && SearchString2=="")
{
 ResultDiv.innerHTML="검색어를 넣어주세요";
 return;
}
else if (SearchString == "" )
{
while (!IslandName.recordset.EOF)
 {
   TCString=IslandName.recordset("교수").value;

  if (TCString.toUpperCase().indexOf(SearchString2)>=0)
      ResultHTML+= IslandName.recordset("과목명")
          + " , "
          + IslandName.recordset("분반")
          + "반 , "
          + IslandName.recordset("교수")
          + "교수님 , "
          + IslandName.recordset("학점")
          + "학점 , "
          + IslandName.recordset("학년")
          + "학년 , "
          + IslandName.recordset("강의시간")
   + "
";
IslandName.recordset.moveNext();
 }

}
else if (SearchString2 == "" )
{
  while (!IslandName.recordset.EOF)
 {
   TitleString=IslandName.recordset("과목명").value;

  if (TitleString.toUpperCase().indexOf(SearchString)>=0)
      ResultHTML+= IslandName.recordset("과목명")
          + " , "
          + IslandName.recordset("분반")
          + "반 , "
          + IslandName.recordset("교수")
          + "교수님 , "
          + IslandName.recordset("학점")
          + "학점 , "
          + IslandName.recordset("학년")
          + "학년 , "
          + IslandName.recordset("강의시간")
   + "
";
IslandName.recordset.moveNext();
 }

}
else
{
while (!IslandName.recordset.EOF)
 {
   TCString=IslandName.recordset("교수").value;
TitleString=IslandName.recordset("과목명").value;

  if (TCString.toUpperCase().indexOf(SearchString2)>=0 && TitleString.toUpperCase().indexOf(SearchString)>=0)
      ResultHTML+= IslandName.recordset("과목명")
          + " , "
          + IslandName.recordset("분반")
          + "반 , "
          + IslandName.recordset("교수")
          + "교수님 , "
          + IslandName.recordset("학점")
          + "학점 , "
          + IslandName.recordset("학년")
          + "학년 , "
          + IslandName.recordset("강의시간")
   + "
";
IslandName.recordset.moveNext();
 }


 
 if (ResultHTML=="")
               ResultDiv.innerHTML="일치하는 정보가 없습니다";
 else
   ResultDiv.innerHTML=ResultHTML;

  }

 </script>

 


==========================================================================

+ Recent posts