Js does not refresh new operations on the rows and columns of the table

Source: Internet
Author: User

The code is for reference only. If you force copy the code, modify the page id.
Copy codeThe Code is as follows:
// Query the database's 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 gets the returned value of the RetrieveCitiesByProvinceId method.
Var datas = xmlhttp.responseXML.doc umentElement. getElementsByTagName ("AlterNativeVenues ");
Var nname = document. getElementById ("table1 ");
Var pchildren = nname. childNodes; // clear rows and columns in the table
For (var a = 0; a <pchildren. length; a ++)
{
Nname. removeChild (pchildren [a]);
}
// Add query rows
Var parameter ow = nname. insertRow (0 );
Var aaCell = maid. 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 + "'); \ "> query </span> ";
// Add a title line
Var aRow = nname. insertRow (1 );
ARow. insertCell (0). innerHTML = "";
ARow. insertCell (1). innerHTML = "name ";
ARow. insertCell (2). innerHTML = "Address ";
ARow. insertCell (3). innerHTML = "phone ";
// Add data rows cyclically
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;
}
}
}
}
}
}


// Add selected data
Function AddRowSelectAfter (id, field)
{
// Divide all IDs in the hidden domain and bind the corresponding checked
Var state = false; // determines 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)
{
// You only need to click checkbox to change the value of the hidden domain.
// The id needs to be removed from the hidden control when the status is not selected
Var arrs = document. getElementById (field). value. substr (0, document. getElementById (field). value. length-1). split (',');
// Define a field to obtain the id again
Var newids = "";
For (var arr = 0; arr <arrs. length; arr ++)
{
If (arrs [arr]! = Id. split ('_') [1])
Newids + = arrs [arr] + ",";
}
// Assign a value to the hidden control again
// The last character may 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)
{
// Click to change the selected status to non-click to remove the selected venue
Document. getElementById (id). checked = false;
// Set the id for tr 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 gets the returned value of the RetrieveCitiesByProvinceId method.
Var datas = xmlhttp.responseXML.doc umentElement. 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 = "name ";
FirstRow. insertCell (1). innerHTML = "Address ";
FirstRow. insertCell (2). innerHTML = "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. removeChild (obj. parentNode. parentNode)
Var nname = document. getElementById ("table2 ");
If (nname. rows. length = 1)
{
Nname. deleteRow (0 );
}
// If the list above does not exist after the 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 id needs to be removed from the hidden control when the status is not selected
Var arrs = document. getElementById (field). value. substr (0, document. getElementById (field). value. length-1). split (',');
// Define a field to obtain the id again
Var newids = "";
For (var arr = 0; arr <arrs. length; arr ++)
{
If (arrs [arr]! = Id)
Newids + = arrs [arr] + ",";
}
// Assign a value to the hidden control again
// Assign a value to the hidden control again
// The last character may 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;
}

Related Article

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.