ASP + jquery editable table update to database

Source: Internet
Author: User

The customer asked the backend to directly click Modify data. jquery can be easily implemented, but the process was not so smooth. During the debugging process, it was found that JS scripts must be used to introduce them.
Type = "text/JavaScript" instead of Language = "JavaScript" or type = "JavaScript ".

1. In order to facilitate the demonstration, the data is displayed statically;

<! Doctype HTML public "-// W3C // DTD xhtml0 transitional //" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> jquery implements editable tables </title>
<Link href = "edittable.css" rel = "stylesheet" type = "text/CSS"/>
<SCRIPT src = "jquery. js" type = "text/JavaScript"> </SCRIPT>

</Head>
<Body>
<Table>
<Tr> <TH> 1 </Th> <TH> 2 </Th> <TH> 3 </Th> <TH> 4 </Th> <TH> 5 </Th> </tr>
<Tr>
<TD> 1235467 </TD>
<TD> 987654321 </TD>
<TD> 987654321 </TD>
<TD> 123546789 </TD>
<TD> 987654321 </TD>
</Tr>
<Tr>
<TD> 12354678 </TD>
<TD> 987654321 </TD>
<TD> 987654321 </TD>
<TD> 123546789 </TD>
<TD> 987654321 </TD>
</Tr>
<Tr>
<TD> 123546789 </TD>
<TD> 987654321 </TD>
<TD> 987654321 </TD>
<TD> 123546789 </TD>
<TD> 987654321 </TD>
</Tr>
</Table>
</Body>
</Html>
<SCRIPT type = "text/JavaScript">
$ (Function () {// equivalent to adding an onload event to the body tag of the page
// Find all TD nodes
VaR TDS = $ ("TD ");
// Add a click event to all TD
TDS. Click (function (){
// Obtain the object of the current click
VaR TD = $ (this );
// Extract the text content of the current TD and save it
VaR oldtext = TD. Text ();
// Create a text box and set the value of the text box to the saved value.
VaR input = $ ("<input type = 'text' value = '" + oldtext + "'/> ");
// Set the content of the current TD object to input
Td.html (input );
// Set the Click Event of the text box to invalid
Input. Click (function (){
Return false;
});
// Set the text box style
Input.css ("border-width", "0 ");
Input.css ("font-size", "16px ");
Input.css ("text-align", "center ");
// Set the text box width to equal to the width of TD
Input. Width (TD. Width ());
// Trigger the all-selected event when the text box gets the focus
Input. Trigger ("Focus"). Trigger ("select ");
// Changes to text when the text box loses focus
Input. Blur (function (){
VaR input_blur = $ (this );
// Save the content of the current text box
VaR newtext = input_blur.val ();
Td.html (newtext );
});
// Responds to Keyboard Events
Input. keyup (function (event ){
// Obtain the key value
VaR keyevent = event | window. event;
Var key = keyevent. keycode;
// Obtain the current object
VaR input_blur = $ (this );
Switch (key)
{
Case 13: // press enter to save the content of the current text box
VaR newtext = input_blur.val ();
Td.html (newtext );
VaR tdchs = TD. Parent ("TR"). Children ("TD ");
VaR I = tdchs. eq (0). Text ();
VaR c = TD. ATTR ("name ");
$. Post ("Save. asp? Id = "+ I +" & Column = "+ C +" & value = "+ newtext, null, function (data ){
Alert (data );
});
Break;

Case 27: // Press ESC to cancel the modification and convert the text box to text.
Td.html (oldtext );
Break;
}
});
});
});
</SCRIPT>

2. Update to database save. asp

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> edit address book </title>
<LINK rel = "stylesheet" href = "images/cssadmin.css">
<SCRIPT type = "text/JavaScript" src = "../script/admin. js"> </SCRIPT>
</Head>
<! -- # Include file = "../include/Const. asp" --> card and board

<! -- # Include file = "../include/connsitedata. asp" -->

<Body>
<%
Dim ID, Col, Val
Id = request. querystring ("ID ")
Col = request. querystring ("column ")
Val = request. querystring ("value ")
Dim rs
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * From ameav_contact where id =" & ID
Rs. Open SQL, Conn, 1, 3

RS (COL) = Val

Rs. Update
Rs. Close
Set rs = nothing
Response. Write "updated"

%>
</Body>
</Html>

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.