jquery Automatic fill check box is the check box true_jquery

Source: Internet
Author: User
Tags stringbuffer
jquery automatically fills the check box with the check box (true), then gets the list of check options by Ajax, and then the options in the list are typed.
Copy Code code as follows:

Dropdown box <select name= "Makemodule" id= "Makemodule" style= ' width:130px ' onchange= ' makemoduleselected ' () ' >
<option value= ' 1 ' >1</option>
</select>

Select Change, triggering function makemoduleselected (), the function is as follows:
Copy Code code as follows:

This event is triggered when the template Drop-down box changes (onchange).
function makemoduleselected () {
ClearAll (' property ');
var Modtitlecode = $ ("#makemodule"). Val ();
$.ajax ({
URL: ' indexstatisticsaction_getselect.jsp ',
Data: {page: ' clientindexstatistics.jsp ', Method: ' Get_subname_en ', Modtitlecode:modtitlecode},
Success:function (Result) {
Return information based on result to determine if login succeeded
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);
}
});
});
}
});
}

The function sends a request to indexstatisticsaction_getselect.jsp via Ajax, returns a string, separates the modified string into an array of strings, and then traverses the tag <div class= "Indexstatistics "> The label below, with the associated label, is ticked (true). The relevant code for INDEXSTATISTICSACTION_GETSELECT.JSP is as follows:
Copy Code code as follows:

//get template corresponding metric
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.executequery (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 ();
}

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.