javascript - How to get $_POST working with my editable jquery table? -
i have editable html table i've got working, can click cells , edit text, can't post values well.
i know there's problem 5 lines of code under comment on script.js
test.php
<h2><u>edit</u></h2> <form action="ajax/name.php" name="edit_template_form" id="edit_template_form" method="post"> <?php print "<table border=\"1\" class=\"editabletable\"> <tr> <th>template name</th> <th>template description</th> </tr>"; foreach($res $row){ $temp_description = $row['template_description']; echo "<tr>"; echo "<td id=\"edit_name\" name=\"edit_name\">". $row['template_name']. "</td>"; echo "<td id=\"edit_template\" name=\"edit_template\">". nl2br($temp_description). "</td>"; echo "<tr/>"; } print "</table>"; ?> </form> <div id="template_edit"></div>
name.php
if (isset($_post['edit_template'])) { $template_edit = $db->escape($_post['edit_template']); $user = $db->escape($user); $db->update('templates', array('template_description' => $template_edit), 'and userid="'.$user.'"'); echo $_post['edit_template']; } if (isset($_post['edit_name'])) { $template_name = $db->escape($_post['edit_name']); $user = $db->escape($user); $db->update('templates', array('template_name' => $template_name), 'and userid="'.$user.'"'); echo $_post['edit_name']; }
script.js
$(function () { $("td").dblclick(function () { var originalcontent = $(this).text(); $(this).addclass("cellediting"); $(this).html("<input type='text' value='" + originalcontent + "' />"); $(this).children().first().focus(); $(this).children().first().keypress(function (e) { if (e.which == 13) { //post values var edit_template = $('#edit_template').val(); var edit_name = $('#edit_name').val(); $.post('ajax/name.php', {edit_name: edit_name, edit_template: edit_template}, function(data) { $('div#template_edit').text(data); }); var newcontent = $(this).val(); $(this).parent().text(newcontent); $(this).parent().removeclass("cellediting"); } }); $(this).children().first().blur(function(){ $(this).parent().text(originalcontent); $(this).parent().removeclass("cellediting"); }); }); });
javascript php jquery html
No comments:
Post a Comment