SoFunction
Updated on 2025-03-09

ajax java implements automatic completion function


var xmlHttpRequest;
var table;
var tbody;
var div;
var input;
var curIndex;
var size;
var r_userId;
function createXMLHttpRequest(){
if(){
xmlHttpRequest = new ActiveXObject("");
}else if(){
xmlHttpRequest = new XMLHttpRequest();
}
}
//Send a request
function findNames(){
if(==38||==40){
}else{
if(>0){
createXMLHttpRequest();
var url = encodeURI(encodeURI("/?module=posts&action=findDept&names="+));
("GET",url,true);
=processMatchResponse;
(null);
}else{
clearNames();
}
}

}
function processMatchResponse(){
if(==4){
if(==200){
//alert();
//var id = ("id");
var dept = ("dept");
var id = ("id");

setNames(dept,id);

}else{
("The page you requested has an exception!");
}
}
}
function setNames(depts,ids){
clearNames();
size = ;
if(size>0){
= "visible";
var row,col1,col2,span;

for(var i = 0;i < size;i++){
row = ("tr");
col1 = ("td");
= depts[i].;
col2 = ("td");
("align","right");
("id","col2");
("width","5%");
span = ("span");
= ids[i].;
= "none";
(span);


(col1);
(col2);
= function(){
= 'mouseOut';
}
= function(){
clearSelected();
= 'mouseOver';
curIndex = ;
}
= function(){
= [0].innerText;
r_userId.value = [curIndex].cells[1].innerText;
clearNames();
};
(row);
}
row = ("tr");
col2 = ("td");
col1 = ("td");
("align","right");
link = ("a");
= "javascript:clearNames();";
= "Close";
(link);
(col1);
(col2);
(row);
}
}
function setPosition(){
input = ("names");
r_userId = ("r_userId");
table = ("table");
div = ("div");
tbody = ("tbody");

= -2;
= "gray 1px solid";
= getLeft(input);
= getTop(input)++6;

curIndex = -1;
();//+","+
}
function clearNames(){
var ind = ;
for(i=ind-1;i>=0;i--){
([i]);
}
="hidden";
curIndex = -1;
}
function clearSelected(){
var ind = ;
for(var i = ind-1;i>=0;i--){
[i].className = "mouseOut";
}
}
function keyDown(){
if(=="visible"){
if( ==38){
if(curIndex>=0){
[curIndex].className='mouseOut';
curIndex = curIndex-1;
if(curIndex>=0){
[curIndex].className = 'mouseOver';
= [curIndex].cells[0].innerText;
r_userId.value = [curIndex].cells[1].innerText;
}
}
}
if(==40){
if(curIndex<size-1){
if(curIndex>=0){
[curIndex].className = 'mouseOut';
}
curIndex = curIndex+1;
[curIndex].className = 'mouseOver';
= [curIndex].cells[0].innerText;
r_userId.value = [curIndex].cells[1].innerText;
}else{
[curIndex].className = 'mouseOut';
curIndex = -1;
}
}
}
}
//Get the vertical coordinate of the element
function getTop(e){
var offset=;
if(!=null) offset+=getTop();
return offset;
}
//Get the horizontal axis of the element
function getLeft(e){
var offset=;
if(!=null) offset+=getLeft();
return offset;
}