Js does not refresh the rows and columns of the table
- 2020-03-30 02:30:19
- OfStack
The code is for reference only. Please change the page id if copying is forced
//Query the database for qualified data
function SelectAlterNativeVenues(field)
{
var xmlhttp;
var pid = document.getElementById("nameandaddress").value;
var url = "${RetrieveURL}?accessorType=${AccessorType}";
url = url+"&method=RetrieveSelectResult&NameAndAddress="+escape(pid);
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE
}
if (xmlhttp != null)
{
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("If-Modified-Since", "0");
xmlhttp.send(null);
xmlhttp.onreadystatechange = function processRefreshUsers() //Registration method
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200)
{
//ResponseXML access to perform RetrieveCitiesByProvinceId methods return values
var datas = xmlhttp.responseXML.documentElement.getElementsByTagName("AlterNativeVenues");
var nname = document.getElementById("table1");
var pchildren = nname.childNodes;//Clear the rows and columns in the table
for(var a=0; a<pchildren.length; a++)
{
nname.removeChild(pchildren[a]);
}
//Add query row
var aaRow=nname.insertRow(0);
var aaCell=aaRow.insertCell(0);
aaCell.innerHTML="<input type='text' name='nameandaddress' id='nameandaddress'/>";
aaRow.insertCell(1).innerHTML="<span style="cursor:pointer;border:1px" name="submit" onclick="SelectAlterNativeVenues('"+field+"');" > The query </span>";
//Add a header line
var aRow=nname.insertRow(1);
aRow.insertCell(0).innerHTML="";
aRow.insertCell(1).innerHTML=" The name of the ";
aRow.insertCell(2).innerHTML=" address ";
aRow.insertCell(3).innerHTML=" The phone ";
//Loop to add rows of data
for (i = 0; i < datas.length; i++)
{
var Id = datas[i].getElementsByTagName("Id")[0].firstChild.nodeValue;
var Name = datas[i].getElementsByTagName("Name")[0].firstChild.nodeValue;
var Address=datas[i].getElementsByTagName("Address")[0].firstChild.nodeValue;
var Phone=datas[i].getElementsByTagName("Phone")[0].firstChild.nodeValue;
var aNewRow=nname.insertRow(i+2);
aNewRow.insertCell(0).innerHTML="<input type="checkbox" id="AlterNativeVenues_"+Id+"" name="AlterNativeVenues_"+Id+"" onclick="AddRowSelectAfter('AlterNativeVenues_"+Id+"','"+field+"')" />";
aNewRow.insertCell(1).innerHTML=Name;
aNewRow.insertCell(2).innerHTML=Address;
aNewRow.insertCell(3).innerHTML=Phone;
}
}
}
}
}
}
//Adds selected data
function AddRowSelectAfter(id,field)
{
//Divide all the ids in the hidden field and then bind the corresponding checked
var state=false; //Determine whether the following list exists
var _hiddenId=document.getElementById(field).value.substr(0,document.getElementById(field).value.length-1).split(',');
for(j=0;j<_hiddenId.length;j++)
{
if(_hiddenId[j]==id.split('_')[1])
{
state=true;
}
}
if(state==false)
{
//Just click on the checkbox and change the value of the hidden field once
//The unselected state requires the id to be removed from the hidden control
var arrs=document.getElementById(field).value.substr(0,document.getElementById(field).value.length-1).split(',');
//Define a field to retrieve the id
var newids="";
for(var arr=0;arr<arrs.length;arr++)
{
if(arrs[arr]!=id.split('_')[1])
newids+=arrs[arr]+",";
}
//Reassign the hidden control
//The last character might be,
var fh=newids.substr(newids.length-1,newids.length);
if(fh==",")
document.getElementById(field).value=newids.substr(0,newids.length-1);
else
document.getElementById(field).value=newids;
if(document.getElementById(id).checked==false)
{
//Select state click to change to non-point state to remove the selected venue
document.getElementById(id).checked=false;
//Set the tr id to delete tr
document.getElementById("table2").deleteRow(document.getElementById("NewRow_"+id.split('_')[1]).rowIndex);
}
else
{
document.getElementById(id).checked=true;
var input =document.getElementById(field);
var xmlhttp;
var url = "${RetrieveURL}?accessorType=${AccessorType}";
url = url+"&method=SelectResult&id="+id;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE
}
if (xmlhttp != null)
{
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("If-Modified-Since", "0");
xmlhttp.send(null);
xmlhttp.onreadystatechange = function processRefreshUsers() //Registration method
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200)
{
//ResponseXML access to perform RetrieveCitiesByProvinceId methods return values
var datas = xmlhttp.responseXML.documentElement.getElementsByTagName("AlterNativeVenues");
var nname = document.getElementById("table2");
nname.style.width="560px";
if(nname.rows.length==0&&datas.length>0)
{
//The first line
var firstRow=nname.insertRow(0);
firstRow.id="NewRow_0";
firstRow.insertCell(0).innerHTML=" The name of the ";
firstRow.insertCell(1).innerHTML=" address ";
firstRow.insertCell(2).innerHTML=" The phone ";
firstRow.insertCell(3).innerHTML=" operation ";
}
for (i = 0; i < datas.length; i++)
{
var Id = datas[i].getElementsByTagName("Id")[0].firstChild.nodeValue;
var Name = datas[i].getElementsByTagName("Name")[0].firstChild.nodeValue;
var Address=datas[i].getElementsByTagName("Address")[0].firstChild.nodeValue;
var Phone=datas[i].getElementsByTagName("Phone")[0].firstChild.nodeValue;
var aNewRow=nname.insertRow(nname.rows.length);
aNewRow.id="NewRow_"+Id;
var oneCell=aNewRow.insertCell(0);
oneCell.innerHTML=Name;
oneCell.width=140;
var twoCell=aNewRow.insertCell(1);
twoCell.innerHTML=Address;
twoCell.width=280;
var threeCell=aNewRow.insertCell(2);
threeCell.innerHTML=Phone;
threeCell.width=100;
var fourCell=aNewRow.insertCell(3);
fourCell.innerHTML="<span id="span_"+Id+"" onclick="DeleteRow('"+Id+"',this,'"+field+"')"> delete </span>";
fourCell.width=40;
if(input.value!="")
input.value+=",";
input.value+=Id;
}
}
}
}
}
}
}
}
function DeleteRow(id,obj,field)
{
obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode)
var nname = document.getElementById("table2");
if(nname.rows.length==1)
{
nname.deleteRow(0);
}
//Not in the above list after a query has been stored in the database
if(document.getElementById("AlterNativeVenues_"+id)!=null||document.getElementById("AlterNativeVenues_"+id)!=undefined)
{
if(document.getElementById("AlterNativeVenues_"+id).checked==true)
{
document.getElementById("AlterNativeVenues_"+id).checked=false;
}
}
//The unselected state requires the id to be removed from the hidden control
var arrs=document.getElementById(field).value.substr(0,document.getElementById(field).value.length-1).split(',');
//Define a field to retrieve the id
var newids="";
for(var arr=0;arr<arrs.length;arr++)
{
if(arrs[arr]!=id)
newids+=arrs[arr]+",";
}
//Reassign the hidden control
//Reassign the hidden control
//The last character might be,
var fh=newids.substr(newids.length-1,newids.length);
if(fh==",")
{
document.getElementById(field).value=newids.substr(0,newids.length-1);
}
else
document.getElementById(field).value=newids;
}