2011-02-16 9 views
0

두 개의 드롭 다운 메뉴가 있습니다. 하나는 모든 계정 아이디이고 하나는 해당 이메일 아이디입니다. 계정 ID에서 항목을 하나 선택하면 해당 드롭 다운에서 해당 이메일 ID를 자동으로 선택해야합니다. (계정 id와 email-id는 1 대 1의 관계 선박이다. 첫번째 accound id는 첫 번째 email id에 해당한다.) 어떻게 JSP로 할 수 있는가?jsp의 다른 드롭 다운 목록에서 선택한 항목을 기반으로 드롭 다운 목록에서 선택

내 여기에 드롭 다운을 참조하십시오

<td> 
1. Member Account Number 
    <span class="bodyCopy"> 
     <font color="#ff0000"> * </font> 
    </span>: 
    <html:select name="DataForm" 
       property="Member.accountNumber" 
       styleClass="formContent" 
      style="width:80px"> 

     <html:options collection="<%= WorkConstants.RENewDropdowns.PACCT %>" 
         property="value" 
         labelProperty="label" 
         styleClass="formContent"/> 
    </html:select> 
</td> 

이메일 ID가 여기에 있습니다 :

<td> 
3. Member <br>E-mail Address:<br /> 
    <span class="bodyCopy"></span> 

    <html:select name="DataForm" 
       property="Member.emailAddress.emailAddress" 
       style = "width:150px" 
       styleClass="formContent"> 

    <html:options collection="<%= WorkConstants.RENewDropdowns.PEMAIL %>" 
         property="value" 
         labelProperty="label" 
         styleClass="formContent"/> 
</html:select> 
</td> 

답변

1

그렇게 할 수있는 방법이 많이 있습니다. 기본 개념은 javascript (또는 jQuery 또는 다른 AJAX 프레임 워크)를 사용하여 양식의 작업을 "comboUpdate"또는 무언가로 변경하고 해당 양식을 제출하는 것입니다. 작업은 두 번째 콤보 만로드하고 같은 페이지로 전달합니다.

1

안녕하세요 선택 상자를 사용하여 데이터베이스에서 값을 검색하기위한 Ajax를 사용, 이것은 당신에게

<%@page import="java.sql.*"%> <html> <head> <script language="javascript" type="text/javascript"> //AJAX code for retrieving dates from database var xmlHttp; var xmlHttp; function showEmp(str){ if (typeof XMLHttpRequest != "undefined"){ xmlHttp= new XMLHttpRequest(); } else if (window.ActiveXObject){ xmlHttp= new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlHttp==null){ alert("Browser does not support XMLHTTP Request"); return; } var url="selEmp.jsp"; url +="?count=" +str; xmlHttp.onreadystatechange = stateChange; xmlHttp.open("GET", url, true); xmlHttp.send(null); } function stateChange() { if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("batchdate").innerHTML=xmlHttp.responseText } } </script> </head> <body> <select name='batch' onchange="showEmp(this.value)"> <option value="none">Select</option> <% Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://192.168.40.120:3306/cjet","root","root"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("Select * from cjet.batch"); while(rs.next()){ %> <option value="<%=rs.getString("bname")%>"><%=rs.getString("bname")%></option> <% } %> </select> <br> <div id='batchdate'> <select name='batchdate' onchange="showCustomer(this.value)"> <option value='-1'></option> </select> </div> </body> </html> 

2.retrieve.jsp

<%@page import="java.sql.*"%> 
<% 
String no=request.getParameter("count"); 
String buffer="<select name='batchdate' onchange='showCustomer(this.value)'><option value='-1'>Select</option>"; 
try{ 
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
Connection con = DriverManager.getConnection("jdbc:mysql://192.168.40.144:3306/cjet","root","root"); 
Statement stmt = con.createStatement(); 
ResultSet rs = stmt.executeQuery("Select * from cjet.batchdate where bname='"+no+"' "); 
while(rs.next()){ 
buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString("courseID")+" </option>"; 
}         
buffer=buffer+"</select>"; 
response.getWriter().println(buffer); 
} 
catch(Exception e) 
{ 
System.out.println(e); 
} 
%> 
1.mainpage.jsp

도움이 될
관련 문제