Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing a <tr> id to jQuery
    primarykey
    data
    text
    <p>I'm still learning jQuery and I ran into a problem. I have a table with 50+ rows. Each is labeled with an id.</p> <pre><code>&lt;tr id="51"&gt; </code></pre> <p>This id is the database id and I need to pass it to jQuery and submit it along with an AJAX request.</p> <pre><code> $($location).click(function () { var $currentSelection = $(this); // if there is already an input-field in this TD, return... if($currentSelection.find('select').length &gt; 0) return; $currentSelection.html(''); $('&lt;select id="selectLocation" onChange="locationSubmit()"/&gt;') .attr('name', 'location') .append('&lt;option&gt;Location 1&lt;/option&gt;', '&lt;option&gt;Location 2&lt;/option&gt;', '&lt;option&gt;Location 3&lt;/option&gt;') .appendTo(this); }); </code></pre> <p><code>locationSubmit()</code></p> <pre><code>function locationSubmit(){ var $selectLocation = $('#selectLocation').val(); var $selectId = $(this).val('tr#id'); //stuck here alert($selectId); $.ajax({ url: '/ajax/training-update.php', data: { action: $selectLocation, courseid: $selectId }, type: 'POST', success: function(output) { alert(output); } }); } </code></pre> <p>the alert in <code>locationSubmit()</code> is returning [object Object]. How do I pass the value of <code>tr#id</code> to <code>locationSubmit()</code> and send it via AJAX?</p> <p>EDIT - HTML</p> <pre><code>&lt;tr id="51"&gt; &lt;td&gt;&lt;a href="/link/goes/here.php?course_id=5&amp;id=51"&gt;course name&lt;/a&gt;&lt;/td&gt; &lt;td&gt; &lt;span class="rowStartDate" id="rowStartDate151"&gt;09/10/12&lt;/span&gt; - &lt;span class="rowEndDate" id="rowEndDate151"&gt;09/14/12&lt;/span&gt; &lt;/td&gt; &lt;td class="location"&gt;Location 2&lt;/td&gt; &lt;td class="status"&gt;open&lt;/td&gt; &lt;/tr&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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