Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Relative Values in Each Loop jQuery
    primarykey
    data
    text
    <p>I'm having an issue pulling the relative values in .each() loop in jQuery. I have a series of table rows that have an text input and a radio button next to them. I want to loop through each row, and if the radio button is selected, save the value for the text input.</p> <p>However, so far whenever I run my loop, it seems to recognize that one of the radio values is selected, and then it automatically saves the first input, regardless of which row. I thought that by running through each row, the code would only be executed in that particular rows HTML -- I believe it's touching all the rows instead. Can anyone help?</p> <p>Here's my jQuery:</p> <pre><code>$('#valueTable tbody tr').each( function() { //$(this).css('background', 'blue'); if($('td input[name=DefaultVal]:checked').size() &gt; 0){ $('td input[name=DefaultVal]:checked').parent().css('background', 'red') selectedDefVal = $('td:first-child input[name=valueTextField]').val(); //alert(selectedDefVal) } else { alert('not checked') } }); </code></pre> <p>Here's my HTML:</p> <pre><code>&lt;table border="0" id="valueTable"&gt; &lt;tr&gt; &lt;td width="70%" style="white-space: nowrap;"&gt;&lt;input size="80" type="text" name="valueTextField" placeholder="Enter Value" value="" &gt;&lt;/td&gt; &lt;td width="70%" class="default_container"&gt;Default &lt;input type="radio" name="DefaultVal" checked="true" class="defaultValFind" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="70%" style="white-space: nowrap;"&gt;&lt;input size="80" type="text" name="valueTextField" placeholder="Enter Value" value="2" &gt;&lt;/td&gt; &lt;td width="70%" class="default_container"&gt;Default &lt;input type="radio" name="DefaultVal" class="defaultValFind" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="70%" style="white-space: nowrap;"&gt;&lt;input size="80" type="text" name="valueTextField" placeholder="Enter Value" value="fffffff" &gt;&lt;/td&gt; &lt;td width="70%" class="default_container"&gt;Default &lt;input type="radio" name="DefaultVal" class="defaultValFind" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </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.
    1. This table or related slice is empty.
    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