Home > Web Front-end > JS Tutorial > body text

jquery dynamic loading select drop-down box sample code_jquery

WBOY
Release: 2016-05-16 17:09:43
Original
1118 people have browsed it

As the title says, go directly to the code and learn in practice.

Copy code The code is as follows:

jquery implements dynamic loading select drop-down option

< /head>

Drop-down box

When the above html is loaded, due to If the onload attribute is set in the body tag, its corresponding javascript function will run. Finally, we go to the function makemoduleSelect(). Let’s take a look at this function:

url attribute, which is similar to the AJAX jump url. Here I use jsp page (indexStatisticsAction_getSelect.jsp) under the same path, which will be shown below;
data attribute, which will be used as a parameter of the request and obtained by request;
success attribute, which indicates that the jquery ajax request returns successfully The code that will be executed, where $("#makemodule") refers to the drop-down box.

The following is the jsp corresponding to the url requested by ajax. The JDBC related packages are deleted here and imported by yourself. I won’t go into details about JDBC. Code the business logic as needed.
Copy code The code is as follows:

<%@ page import="java.util. *"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.io.PrintWriter"%>
< %
String userId = (String) session.getAttribute("userid");
String method = request.getParameter("method");
String fromPage = request.getParameter("page");
String sql1 = "select modtitlename,modtitlecode from makemodule where userid = '?userId?' and modulename_en='?modulename_en?' group by modtitlename ";
System.out.println("---getting select_option from: " fromPage "----" new Date());

//Get template options
if(method.equals("get_modtitlecode")){
String sql = sql1.replace( "?userId?",userId);
if(fromPage.equals("acindexStatistics.jsp")){
sql = sql.replace("?modulename_en?","acsta");
} else if(fromPage.equals("apindexStatistics.jsp")){
sql = sql.replace("?modulename_en?","apsta");
}else if(fromPage.equals("clientindexStatistics.jsp ")){
sql = sql.replace("?modulename_en?","terminalsta");
}
System.out.println(sql);
StringBuffer rsOption = new StringBuffer() ;
Db db = new Db();
try {
db.prepareQuery();
ResultSet rs = db.executeQuery(sql);
while (rs!=null && rs .next()) {
rsOption.append("

The above sql statement will take out two values, which are the display value and the true value of the select drop-down box, and set an
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template