The AJAX submission data determines whether the employee number exists and automatically fills in the employee name corresponding to the employee number.

Source: Internet
Author: User

JavaScript events and Ajax required in JSP pages
1 <Scripttype= "Text/javascript">2 functionCheckempno (ID) {3     varEmpnovalue=document.getElementById (ID). value;4 $.ajax ({5 Type:'Post',6 URL:'employee_checkempnoandempname.htm',7 Data:'empno='+Empnovalue,8 Success:function(Result) {9                 if(Result=="the user name does not exist! "){Ten Alert ("the user name does not exist! "); One document.getElementById (ID). Value=""; A document.getElementById ("EmpName"). Value=""; - document.getElementById (ID). focus (); -                 }Else{ the document.getElementById ("EmpName"). Value=result; - document.getElementById ("Entrancestart"). focus (); -                 }  -     }); + </Script> - <form> +     <Table> A       <TR> at         <TD><inputID= "EmpNo"onblur= "Checkempno (this.id)"type= "text"name= "EmpNo" /></TD> -         <TD><inputID= "EmpName"type= "text"name= "EmpName" /></TD> -       </TR> -     </Table> - </form>        
The code required for the background action:

PublicClasee empactionextendsactionsupport{ PublicString Checkempnoandempname ()throwsException {httpservletrequest request=servletactioncontext.getrequest (); HttpServletResponse respons=Servletactioncontext.getresponse (); String EmpNo= Request.getparameter ("EmpNo")///Gets the empno Respons.setcontenttype of the action that the page submits to the background ("Text/html;charset=utf-8");//Set String SENDSTR for the character set of the response= ""; List<EmployeeInfo> employeeinfolist = This. Empservice.checkempno (EmpNo);//Call the business to query this user based on the EMPNO layer Try{PrintWriter out=respons.getwriter ();//More To print objectsif(Employeeinfolist.size () >0) {Sendstr= Employeeinfolist.get (0). Getempname (); } Else{sendstring= "The user name does not exist!" "; } out.print (SENDSTR);//The background dynamic SENDSTR output to the JSP page Out.flush (); Out.close (); } Catch(Exception e) {e.printstacktrace (); } return NULL; }}

The AJAX submission data determines whether the employee number exists and automatically fills in the employee name corresponding to the employee number.

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.