Jquery achieves two-level interaction of the drop-down menu using json objects to display the association from DB values _ javascript skills

Source: Internet
Author: User
This article mainly introduces jquery's implementation of the second-level interaction of the drop-down menu using json objects to display the association from the DB value. If you need it, you can refer to the use of struts2 and Ajax to implement the transmission of json objects, then implement level-2 Association of menus

The following is the source code of my js file:

The Code is as follows:


Var mail = {
// Initialization
Init :{
// Initialize data
Initdata :{
Did :'',
Ttitle :'',
Sendpassword :'',
Description :''
},
// Initialization event
Initevent :{
DataEvent: function (){
$ ("# Did"). unbind ("change"); // obtain the level-1 menu and bind events
$ ("# Did"). bind ("change", function (){
// Alert ($ (this). val ());
Mail. init. initdata. did = $ (this). val ();
// Alert (mail. init. initdata. did );
Mail. init. initevent. getuser ();
});
},
Getuser: function (){
$. Post ("mailAction_showUsers? Did = "+ mail. init. initdata. did, null, function (data ){
Var uidoption = $ ("# uid"); // obtain the level-2 menu
Uidoption. empty (); // clear the list
For (var I = 0; I // Fill the option with the loop
Uidoption. append (" "+ Data. users [I]. username +"");
}
});
},
SubmitCheck: function (){
$ ("# Send"). unbind ("click ");
$ ("# Send"). bind ("click", function (){
Mail. init. initdata. description = $ ("input [type = 'texta']"). text ();
Mail. init. initdata. sendpassword = $ ("input [name = 'sendpassword']"). val ();
Mail. init. initdata. ttitle = $ ("input [name = 'ttitle']"). val ();

If (mail. init. initdata. sendpassword = ""){
Alert ("enter the password! ");
Return false;
}
Else if (mail. init. initdata. ttitle = ""){
Alert ("enter a topic! ");
Return false;
}
Else if (mail. init. initdata. description = ""){
Alert ("Enter the content! ");
Return false;
}
Else
Return true;
});
}
}
}
}

$ (). Ready (function (){
Mail. init. initevent. DataEvent ();
Mail. init. initevent. submitCheck ();

});


This is the background action:

The Code is as follows:


Private int did;
Public String getDid (){
...
}
Public void setDid (Strign did ){
...
}
Public String showUsers (){

Users = (ArrayList ) This. userService. getUsersByDid (did );
System. out. println (users. size () + "...");
Return SUCCESS;
}


Struts. xml configuration:

The Code is as follows:









Front-end jsp page:

The Code is as follows:


Recipient




This is implemented and run:

Write to persons in need... Reference
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.