Automatic prompts by using JavaScript + AutoComplete

Source: Internet
Author: User

Imported package:

<SCRIPT type = 'text/JavaScript 'src = 'njs/jquery-AutoComplete/jquery. autocomplete. js'> </SCRIPT>
<LINK rel = "stylesheet" type = "text/CSS" href = "NJS/jquery-AutoComplete/jquery.autocomplete.css"/>

 

JSCode:

 

VaR I = 0;
VaR jtcmnames = ['','', ''];
Function Change (valu ){
// Alert (jtcmnames );
VaR doc_value = valu. value;
If (I = doc_value.length ){
 
} Else {
I = doc_value.length;
Doc_value = encodeuri (valu. Value ));
Createxmlhttp ();
XMLHTTP. Open ("Post", "autocomplete. do? Input_content = "+ doc_value, false );
XMLHTTP. Send (null );
VaR names = XMLHTTP. responsetext;
Jtcmnames = names. Split ("|"); // After receiving the server-side data, we need to parse the data. The data in JSON format is actually an array.
// Alert (jtcmnames );
$ ("# Column04"). AutoComplete (jtcmnames, {matchcontains: True, AutoFill: false });
XMLHTTP. closed;
}
}

 

Struts-config.xml

 

<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype Struts-config public "-// Apache Software Foundation // DTD struts configuration 1.1 //" http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd ">
<Struts-config>
<Form-beans>
 
</Form-beans>
<Action-mappings>
<Action Path = "/AutoComplete" parameter = "#" type = "com. sitech. ismp. iimp. common. action. autocompleteaction "Scope =" request "Validate =" false ">
<Forward name = "default" Path = "/common/getalldealedlist. jsp"/>
</Action>
</Action-mappings>
</Struts-config>

 

 

 

Action:

 

 

Public void AutoComplete (actionmapping mapping,
Actionform, httpservletrequest request,
Httpservletresponse response) throws exception {

String query_value = java.net. urldecoder. decode (request. getparameter ("input_content"), "UTF-8"); // transcode the data. This must be the case because the data is also transferred on the JSP page to maintain consistency.
Tblsys_loginmsg user = (tblsys_loginmsg) request. getsession ()
. Getattribute (tblsys_loginmsg.session_key); // only obtains the current user
String login_id = NULL;
If (user! = NULL )&&! User. Equals ("")){
Login_id = user. getlogin_id ();
}
Request. setcharacterencoding ("UTF-8 ");
Response. setcontenttype ("text/html ");
Response. setcharacterencoding ("UTF-8 ");
Sys_loginmsgdao autocompletedao = new sys_loginmsgdao ();
If (query_value! = NULL &&! Query_value.trim (). Equals ("")){

List autocompletelist = autocompletedao. findtitleforjsname (query_value, login_id );
If (autocompletelist! = NULL &&! Autocompletelist. isempty ()){
Query_value = ibsmutil. getjsarrayfromlist (autocompletelist, "titile ");
Response. getwriter (). append (ibsmutil. getjsarrayfromlist (autocompletelist, "titile "));
Response. getwriter (). Flush ();
Response. getwriter (). Close ();
}
}

}

 

 

The disadvantage of this method is: If you enter the first word, it will not be automatically prompted, only the second input will be prompted, because the first time it is just to assign a value to the variable, the second time, you can read the variables one by one for prompt.

 

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.