The jquery auto-fill check box is used to set the check box to true.

Source: Internet
Author: User

The jquery auto-fill check box is used to set the check box to true, obtain the check Option List through ajax, and then set the options in the list.
Copy codeThe Code is as follows:
Drop-down box <select name = "makemodule" id = "makemodule" style = 'width: 130px 'onchange = 'makemoduleselected () '>
<Option value = '1'> 1 </option>
</Select>

The select function changes and triggers the makemoduleSelected () function. The function is as follows:
Copy codeThe Code is as follows:
// This event (onchange) is triggered when the template drop-down box is changed ).
Function makemoduleSelected (){
ClearAll ('properties ');
Var modtitlecode = $ ("# makemodule"). val ();
$. Ajax ({
Url: 'indexstatisticsaction _ getSelect. jsp ',
Data: {page: 'clientindexstatistics. jsp ', method: 'Get _ subname_en', modtitlecode: modtitlecode },
Success: function (result ){
// Determine whether the logon is successful based on the result returned.
Var results = result. split (",");
// Document. getElementById (results [I]). checked = true;
$ (". IndexStatistics"). each (function (){
$ (This). find ("input"). each (function (){
Var tempVal = $ (this). val ();
For (var I = 0; I <results. length; I ++ ){
If (tempVal = results [I]) $ (this). attr ("checked", true );
}
});
});
}
});
}

This function sends a request to indexStatisticsAction_getSelect.jsp in ajax mode, returns a string, splits the modified string into a string array, and then traverses the labels under the label <div class = "indexStatistics">, if related tags are encountered, check (true ). The Code of indexStatisticsAction_getSelect.jsp is as follows:
Copy codeThe Code is as follows:
// Obtain the metrics corresponding to the template
If (method. equals ("get_subname_en ")){
String modtitlecode = request. getParameter ("modtitlecode ");
If (modtitlecode. equals ("-------") return;
String SQL = sql2.replace ("? Modtitlecode? ", Modtitlecode );
SQL = SQL. replace ("? UserId? ", UserId );
System. out. println (SQL );
StringBuffer subnames = new StringBuffer ();
Db db = new Db ();
Try {
Db. prepareQuery ();
ResultSet rs = db.exe cuteQuery (SQL );
While (rs! = Null & rs. next ()){
Subnames. append (rs. getString ("subname_en "));
Subnames. append (",");
}
Rs. close ();
} Catch (Exception e ){
E. printStackTrace ();
} Finally {
Db. endQuery ();
}
PrintWriter pout = response. getWriter ();
Pout. write (subnames. toString (). substring (0, subnames. length ()-1 ));
Pout. flush ();
Pout. close ();
}

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.