jquery double-click Text to edit and save data

Source: Internet
Author: User
The code is as follows Copy Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
</title> for <title> Test
<script language= "javascript" src= "Demo2/jquery-1.3.2.min.js" ></script>

<body>
<table width= "66%" border= "0" cellspacing= "0" cellpadding= "0" >
<tr>
&LT;TD height= "align=" "Center" ><strong> username </strong></td>
&LT;TD align= "Center" ><strong> Email address </strong></td>
</tr>
<tr>
&LT;TD class= "UNM" uid=1 id= "unm1" filed= "UNM" > User a</td>
&LT;TD class= "Email" uid=1 id= "email1" filed= "email" >usera@domain.con</td>
</tr>
<tr>
&LT;TD class= "UNM" uid=2 id= "unm2" filed= "UNM" > User b</td>
&LT;TD class= "Email" uid=2 id= "email2" filed= "email" >userb@domain.com</td>
</tr>
</table>
</body>

There are 2 custom properties in the TD tag in the HTML code, uid,filed, the first UID is used to represent the ID field in the corresponding table in the database, filed is used to indicate which of the data in the TD represents the field in the table.
Here is the JS code:

JavaScript code

The code is as follows Copy Code

<script language= "JavaScript" >
$ (). Ready (function () {
$ (". Unm,.email"). DblClick (function () {
id=$ (This). attr ("UID");
value=$ (This). text ();
f=$ (This). attr ("field");
text_id=$ (This). attr ("id");
if (value)
{
$ (this). HTML ("<input type= ' text ' id=" +id+ "name=" +f+ "value=" +value+ ">");
$ (". UNM > Input,.email>input"). focus (). blur (function () {

$.ajax ({
Type: "POST",
URL: "save.php",
Data: "id=" +id+ "&type=" +f+ "&value=" +$ ("#" +id). Val (),
Success:function (msg) {$ ("#" +text_id). Text (msg);
});
})

}

})

})

</script>

save.php

PHP code

  code is as follows copy code
<?php   
//Save to Database   
 
if ($_post["type"]== "email")   
{  
   //mysql_query ("Update sometable set email= ' {$_post[" value "]} ' where id={$_post[" id "}");   
}  
 
if ($_post["type"]== "UNM")   
{  
//mysql_query (" Update sometable set unm= ' {$_post[' value '} ' where id={$_post[' id '} ');  
}  
 
E Cho $_post["value"];  
?> 

The


principle is simple: double-click the contents of the ID into input, and then save the same as the ID form post past, and then use PHP to enter the save.

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.