onchange event usages of select in JSP _jsp programming

Source: Internet
Author: User
Tags trim

The example in this article describes the onchange event usage for select in the JSP. Share to everyone for your reference, specific as follows:

<script language = "JavaScript" > var onecount; 
 onecount=0; 
 subcat = new Array (); 
 <% int count = 0; Java.sql.ResultSet rs1 = Dbmanage.executequery ("Select Hydm,zhydm,zhymc from Zhy");//Read data while (Rs1.next ()) {Strin 
 G Selhydm=rs1.getstring ("HYDM"). Trim (); 
 String zhydm=rs1.getstring ("ZHYDM"). Trim (); 
 String zhymc=rs1.getstring ("ZHYMC"). Trim (); 
 %> Subcat[<%=count%&gt] = new Array ("<%=zhydm%>", "<%=selhydm%>", "<%=zhymc%>");//Generate array <% 
 Count = count + 1; 
 } if (Rs1!=null) dbmanage.closeconn (); 
 %> onecount=<%=count%>; 
 function changelocation (id) {document.form1.selzhy.length = 0; 
 var Hydm=id; 
 var i; 
 Document.form1.selzhy.options[0] = new Option (' Select sub-industry category ', '); For (I=0;i < Onecount i++) {if (subcat[i][1] = = HYDM) {DOCUMENT.FORM1.SELZHY.OPTIONS[DOCUMENT.FORM1.SELZHY.L 
 Ength] = new Option (subcat[i][2], subcat[i][0]); }} </script> <table width= border= "0" Cellspacing= "0" cellpadding= "0" align= "center" > <tr> <td width= "180" height= "" align= "right" > select industry Category: </td& 
 Gt &LT;TD width= "<select name=" Selhy "onchange=" Changelocation (document.form1.selhy.options[ Document.form1.selhy.selectedindex].value) "size=" 1 "> <option value=" 2 "> Please select Industry Classification </option> <% rs = 
 Dbmanage.executequery ("SELECT * from Hy"); 
  while (Rs.next ()) {String hydm=rs.getstring ("HYDM"). Trim (); 
 String hymc=rs.getstring ("HYMC"). Trim (); %> <option value= "<%=hydm%>" ><%=hymc%></option> <%} if (Rs!=null) dbmanage.closeconn 
 ();  
 %> </select> </td> </tr> <tr> <td height= "a" align= "right" > select sub Industry category:</td> 
 <td> <select name= "Selzhy" > <option value= "" Selected> Please select sub-industry category </option> </select> </td> </tr> </table> <form name=form1> <select name=province onchange= "CityName" (this.SelectedIndex) "> <option value=" "> Please select Province name </option> </select> <select name=city> <opt Ion value= "" > Please select City name </option> </select> </form> <script language=javascript> var city1 
 = ["Hangzhou", "Ningbo", "Wenzhou", "Shaoxing", "Jinhua", "Huzhou"]; 
 var city2 = ["Nanjing", "Suzhou", "Wuxi", "Changzhou", "Zhenjiang", "Xuzhou"]; 
 var city3 = ["Hefei", "翕 County", "Huangshan", "Qimen", "Xiuning"];  
 var city4 = ["Nanchang", "Jiujiang", "Ganzhou", "Shangrao", "Xinyu", "Jingdezhen"]; 
 var provincename = ["Zhejiang", "Jiangsu", "Anhui", "Jiangxi"]; 
   Function province () {var e = document.form1.province; 
 for (var i=0 i<provincename.length; i++) e.options.add (new Option (provincename[i), provincename[i)); 
   function CityName (n) {var e = document.form1.city; 
   for (var i=e.options.length; i>0; i--) E.remove (i); 
   if (n = = 0) return; var a = eval ("city" + N); 
 Gets the city's array name for (var i=0; i<a.length; i++) E.options.add (new Option (a[i), a[i)); } function Window.onload () {province ();///////////////Lt;/script>

 

I hope this article will help you with JSP programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.