The two-level linkage of the Pull-down menu using the JSON object to display linkage from DB value

Source: Internet
Author: User

  This article mainly introduces the implementation of the jquery drop-down menu two-level linkage using JSON objects from DB value display linkage, need friends can refer to the following

Use STRUTS2 and Ajax to implement JSON object transmission, and then implement menu two-level linkage     Below is my JS file original code:    code as follows: VAR mail={ //initialization   init:{  //initialization of data   initdata:{  did: ',  ttitle: ',  sendpassword: ',  description: '  },  //initialization event   initevent:{  dataevent:function () {  $ ("#did"). Unbind ("change"); Get a level menu, bind event   $ ("#did"). Bind (' Change ', function () { //alert ($ (this). Val ());  mail.init.initdata.did=$ (This). Val ();  //alert (Mail.init.initdata.did);  mail.init.initevent.getuser (); }); },  <span Style = "COLOR: #ff0000;" >getuser:function () {  $.post ("mailaction_showusers?did=" +mail.init.initdata.did,null,function (data) {   var uidoption=$ ("#uid")//Get level Two menu   uidoption.empty ()//Empty list   for (Var i=0;i<data.users.length;i+ +) { //Add option to the inside, through the loop   uidoption.append ("<option value=" +data.users[i].uid+ ">" +data.users[i). Username+ "</option>"); } });</span> },&nbsP Submitcheck:function () {  $ ("#send"). Unbind ("click");  $ ("#send"). Bind ("click", Function () {  mail.init.initdata.description=$ ("input[type= ' textarea ']"). Text ();  mail.init.initdata.sendpassword=$ (" Input[name= ' Sendpassword '). Val ();  mail.init.initdata.ttitle=$ ("Input[name= ' Ttitle ')"). Val ();    if (mail.init.initdata.sendpassword== "") {  alert ("Please enter password!");   Return false; }  else if (mail.init.initdata.ttitle== "") {  alert ("Please enter a theme!") ");  return false; }  else if (mail.init.initdata.description==" ") {  alert (" Enter the content! "). ");  return false; }  else  return true; }); } -} } }    $ (). R Eady (function () {  mail.init.initevent.DataEvent ();  Mail.init.initevent.submitCheck ();   });     This is the backstage action:    code as follows: Private int did;  public String getdid () {  ... }  Public void Setdid (Strign did) {  ... }  PUBlic String showusers () {    users= (arraylist<user>) This.userService.getUsersByDid (did);  System.out.println (users.size () + "...");  return success; }    struts.xml configuration:    code is as follows: <package name= "Users" namespace= "/" extends= "Json-default" >  <action name= "Mailaction_showusers" Method= "Showusers" class= "mailaction" >  <result type= "JSON" ></result>  </action>     </package>    foreground JSP page:    code as follows: <td width= "65px" > Receiver </td>  <td> <s:select list= "departmentlist" listkey= "did" listvalue= "Dname" id= "did" Name= "did" ></s:select >  <s:select list= "users" listkey= "UID" listvalue= "username" id= "UID" name= "UID" ></s:select>   </td> 

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.