日期:2014-05-16  浏览次数:20503 次

[点滴积累]jdbc与js结合的级联下拉列表
代码片段
<td valign="top" ><p align="right">车牌号码:</p></td>
            <td >
          <select size="1" name="CLID"  onchange="javaScript:changelocation(this.value);" style="width:200">
            <option value="">==请选择==</option>
<%
    SQL = "Select CLID,CPHM,CLMC,SJMC from CL_JBXX where 1=1;";

    ResultSet rs_1 = queryData.getResultSet(SQL );

	int iCLID_select = 0;
	String sjmc2 = "";
    while (rs_1.next()){
	  	 iCLID_select = rs_1.getInt("CLID");
    	 sCPHM = rs_1.getString("CPHM");
	     sCLMC = rs_1.getString("CLMC");
    	// sSJMC = rs_1.getString("SJMC");
%>
      <option  <% if (iCLID_select == iCLID)  {%> selected <% } %> value="<%=iCLID_select%>"><%=sCLMC%>(<%=sCPHM%>)</option>
<% } %>
              </select></td>
            <td >
              <p align="right">司机名称:</td>
            <td ><input name="SJMC"   value="<%=sSJMC%>" type="text" maxlength="100" class="tex1" size="20"></td>
          </tr>

<%
     sql =  "Select  CLID,CPHM,CLMC,SJMC  from  CL_JBXX  where  1=1 ;"
     ResultSet rsSelect = queryData.getResultSet(sql );
%>
      <script language = "JavaScript">
        var onecount;
        onecount=0;
        subcat = new Array();
<%	int iCount = 0;
	String sSJMC2="";
         while (rsSelect.next()){
		     iCLID = rsSelect.getInt("CLID");
		     sCPHM = rsSelect.getString("CPHM");
		     sCLMC = rsSelect.getString("CLMC");
		     sSJMC2 = rsSelect.getString("SJMC");
%>
            subcat[<%=iCount%>] = new Array("<%=sSJMC2%>","<%=iCLID%>");
<%
             iCount = iCount + 1;
         }
%>
  onecount=<%=iCount%>;
</script>


 function changelocation(locationid)
     {
         var locationid=locationid;
         var ii;
         for (ii=0;ii < onecount; ii++)
         {
             if  ((subcat[ii][1] == locationid) || (locationid==0) )
             {
                 document.form.SJMC.value = subcat[ii][0];
             }
         }
    }