2011-01-11 4 views
0

클릭 이벤트를 사용하여 선택한 특정 값을 기반으로 팝업 창을 생성하려고합니다. if 문에 문제가있어서 각 특정 옵션 값에 액세스하려고합니다. 여러분 중 누구도 나에게 몇 가지 힌트를 줄 수 있습니까?특정 옵션 값에 액세스하여 팝업 창을 생성하려고 시도했습니다.

 <select id="offices"> 
      <option value="Choose an Office">Choose an Office</option> 
      <option value="Residential Education (ResEd)" >Residential Education (ResEd)</option> 
      <option value="Dean of Students">Dean of Students</option> 
      <option value="Office of Student Affairs">Office of Student Affairs</option> 
      <option value="Vice-Provost of Student Affairs">Vice-Provost of Student Affairs</option> 
     </select> 
</div> 

기능 표시() {

 var officearray = [{ 
      Office: "Residential Education (ResEd)", 
      ID: "725-2800", 
      Description: "The Office of Residential Education is responsible for developing the policies, programs, and staffing which support the intellectual, educational, and community-building activities in student residences. Second Floor. " 
     }, { 
      Office: "Dean of Students", 
      ID: "723-7833", 
      Description: "The Dean of Students office is composed of 13 individual administrative units that are concerned with the general welfare of both undergraduate and graduate students, in and out of the classroom. Second floor." 
     }, { 
      Office: "Office of Student Activities (OSA)", 
      ID: "723-2733", 
      Description: "Services for student organizations, student-initiated major events and programs, and fraternities and sororities. Second floor." 
     }, { 
      Office: "Vice-Provost of Student Affairs", 
      ID: "725-0911", 
      Description: "The Vice Provost for Student Affairs is responsible to the Provost for providing services and programs to undergraduate and graduate students in support of the academic mission of the University. Second floor." 
     }] 

     for(var i = 0; i < officearray.length; i++) { 
      var o = document.getElementById("offices") 
      var oString = o.options[o.selectedIndex].value; 

      newwindow2 = window.open('', 'name', 'height=200, width=150') 
      var tmp = newwindow2.document 
      if (oString == officearray[i].Office) { 
       tmp.writeln(officearray[i].Description) 
      } 

     } 
    } 
    document.getElementsByTagName('option').addEventListener("click",display,false) 
+0

jQuery를 사용하면 큰 도움이됩니다. – Jake

+0

사실, 다른 아이디어가 있습니까? – Isaac

답변

0

응답 해 주셔서 감사합니다. 오히려 onlick 이벤트를 onchange로 변경하고 addEventListener 기간을 없앴습니다. 그런 다음 W3C 호환 이벤트 처리기를 사용하여 변경 이벤트를 처리했습니다.

document.getElementById("offices").onchange=display;

0

내가 당신의 질문을 이해 가정하면, 다음과 마지막 줄을 교체해보십시오 :

var options = document.getElementsByTagName('option'); 
for(var i = 1; i < options.length; i++) { options[i].addEventListener("click", display, false) } 

을 당신의 배열에 또는 addEventListener를 사용하려고 요소, 작동하지 않습니다.

관련 문제