Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery + table row edit - String problem
    text
    copied!<p>I've one problem with editing a row... I wanted to use a button to enter edit mode in the table (generated from php array (data taken from mysql)) </p> <p>I have two rows for each data:</p> <pre><code> &lt;tr class="dataline"&gt; &lt;td&gt;&lt;?=$row-&gt;id; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?=$row-&gt;pl&gt;0 ? '&lt;div id="gain"&gt;' . $row-&gt;pl .'&lt;/div&gt;' : '&lt;div id="loss"&gt;' . $row-&gt;pl . '&lt;/div&gt;';?&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="reason"&gt;&lt;?=$row-&gt;reason;?&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="comment"&gt;&lt;?=$row-&gt;comment;?&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="date"&gt;&lt;?=$row-&gt;cdate; ?&gt;&lt;br /&gt;&lt;?=$row-&gt;ctime; ?&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="date"&gt;&lt;?=$row-&gt;mdate; ?&gt;&lt;br /&gt;&lt;?=$row-&gt;mtime; ?&gt;&lt;/div&gt;&lt;/td&gt; &lt;td colspan="2"&gt;&lt;button id="editlink"&gt;Edit&lt;/button&gt; &lt;button id="deletelink"&gt;Delete&lt;/button&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="editline" style="display:none;"&gt; &lt;form id="&lt;?php echo $row-&gt;id;?&gt;"&gt; &lt;td&gt;&lt;?php echo $row-&gt;id; ?&gt;&lt;input type="hidden" name="id" id="id" value="&lt;?php echo $row-&gt;id;?&gt;" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="pl" name="pl" value="&lt;?=$row-&gt;pl;?&gt;" /&gt;&lt;/td&gt; &lt;td&gt;&lt;textarea id="reason" name="reason"&gt;&lt;?=$row-&gt;reason;?&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;td&gt;&lt;textarea id="comment" name="comment"&gt;&lt;?=$row-&gt;comment;?&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="date"&gt;&lt;?=$row-&gt;cdate; ?&gt;&lt;br /&gt;&lt;?=$row-&gt;ctime; ?&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="date"&gt;&lt;?=$row-&gt;mdate; ?&gt;&lt;br /&gt;&lt;?=$row-&gt;mtime; ?&gt;&lt;/div&gt;&lt;/td&gt; &lt;td colspan="2"&gt;&lt;input id="edit_save" type="Submit" value="Save" /&gt; &lt;/form&gt; &lt;button id="cancellink"&gt;Cancel&lt;/button&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>I attached two jquery statements to it ... </p> <p>1st. one ... changes the row to <pre><code> $("#editlink").click(function() { var datapos = $(this).parent().parent().prevAll().length; var editpos = datapos + 1; $("#data_table tbody tr:eq(" + datapos + ")").hide(); $("#data_table tbody tr:eq(" + editpos + ")").show(); }); </code></pre> <p>Works perfectly.</p> <p>2nd. Suppose to save (POST to PHP script) once the change has been done and reload the page. </p> <pre><code> $("#edit_save").click(function() { var dataString = $("form").serialize(); var editpos = $(this).parent().parent().prevAll().length; var datapos = editpos - 1; $.ajax({ type: "POST", url: "edit", data: dataString, success: function() { $("#lightbox").fadeIn(900); $("#notification-box").show(); $("#notification-box").html("&lt;img src='&lt;?php base_url();?&gt;img/notification.gif'&gt;&lt;p&gt;Saving&lt;/p&gt;"); location.reload(); } }); }); </code></pre> <p>So, the issue I have here is that the dataString is a value of all values generated in the table not the specific row I wanted to edit. </p> <p>I would be really glad if someone can help me with that. </p> <p>Cheers,</p> <p>/Jacek</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload