Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich submit button was pressed?
    primarykey
    data
    text
    <p>In this jsfiddle</p> <p><a href="http://jsfiddle.net/littlesandra88/eGRRb/" rel="nofollow">http://jsfiddle.net/littlesandra88/eGRRb/</a></p> <p>have I submit buttons that are auto-generated. Each table row gets an unique ID number, and if needed each submit button can get the same unique number as well.</p> <p><strong>Question</strong></p> <p>The problem is that there are multiple submit buttons, so how do I know which was pressed?</p> <p><strong>HTML</strong></p> <pre><code>&lt;form action="" method="post"&gt; &lt;table class="alerts tablesorter" id="accTable" cellspacing="0"&gt; &lt;thead&gt; &lt;tr class="header"&gt; &lt;th class="activity-header"&gt; A &lt;/th&gt; &lt;th class="activity-header"&gt; Signed &lt;/th&gt; &lt;th class="activity-header"&gt; &lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr class="row" id="7249"&gt; &lt;td class="activity-data"&gt;7249&lt;/td&gt; &lt;!-- tablesorter can't sort a column with check boxes out-of-the-box, so it needs something to sort on. That is why the span tag is here --&gt; &lt;!-- a jquery script is watching the state of the checkbox, so when clicked the value in the span is updated --&gt; &lt;td class="checkbox"&gt; &lt;span style="display:none;"&gt;0&lt;/span&gt; &lt;input name="signed" type="checkbox" &gt; &lt;/td&gt; &lt;td class="edit-column"&gt; &lt;input value="Save" type="submit" name="7249"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="row" id="61484"&gt; &lt;td class="activity-data"&gt;61484&lt;/td&gt; &lt;td class="checkbox"&gt; &lt;span style="display:none;"&gt;1&lt;/span&gt; &lt;input name="signed" type="checkbox" checked &gt; &lt;/td&gt; &lt;td class="edit-column"&gt; &lt;input value="Save" type="submit" name="61484"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p><strong>JavaScript</strong></p> <pre><code>$(document).ready(function() { $("#accTable").tablesorter(); // :checkbox stops from executing the event on the save button. Same as input[type=checkbox] $('#accTable input:checkbox').click(function() { // insert 1 or 0 depending of checkbox state in the tag before the input tag. In this case &lt;span&gt; is before &lt;input&gt; // this is done so tablesorter have something to sort on, as it doesn't support checkbox sort out of the box. var order = this.checked ? '1' : '0'; $(this).prev().html(order); $(this).parents("table").trigger("update"); }); }); // sends the form content to server side, and stay on page $('form').live('submit', function() { alert('test'); // don't redirect return false; }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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