title: How to select the nth input text box by another inputs id in the same row with jQuery?
body: <p>I have a row that is generated by a code-behind and each row contains tds that contain input text boxes. I need text to appear in a text box 2 tds down from the original input(id=Date) that was selected but based on that selected text box in that same row by it's Id of the input. The issue is that there multiple rows that need to do this, though I made sure they do have separate Ids. So really I need the input's id where the text will appear based on the Date input selected in that row. Essentially, Date needs to appear as a day in associated Day input box. Any help is appreciated!</p>
  
  <p>I have tried the following:</p>
  
  <p><code>var DayId = $("#" + id).closest('input').attr('id');</code></p>
  
  <p><code>var DayId = $("#" + id).closest('tr').find('td:eq(2)').attr('id');</code></p>
  
  <p>The first one seems to work, but only grabs the id of the selected box, not the input with the DayId associated with that selected input in the row. I think the second line is closer but returns undefined.</p>
  
  <p>The Date conversion works fine, but getting it to appear with Day in the "Day" input I haven't figured out.</p>
  
  <pre><code>&lt;script&gt;
      $('body').on('focus', ".datepickerInput", function () {
          $(this).datepicker({
              controlType: "select",
              onSelect: showDay($(this).attr("id"))
          });
      });
  
      function showDay(id) {
          var DayId = $("#" + id).closest('tr').find('td:eq(2)').attr('id')
           alert(DayId)
  
          var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
          var dateVal = "";
          dateVal = $("#" + id).val();
          var x = new Date(dateVal);
          dayOfWeek = weekday[x.getDay()];
          ("#" + DayId).val(dayOfWeek)
      }
  
      showDay()
  &lt;/script&gt;
  
  &lt;table&gt;
   &lt;thead&gt;
    &lt;tr&gt;
     &lt;th&gt;infoA&lt;/th&gt;
     &lt;th&gt;infoB&lt;/th&gt;
     &lt;th&gt;infoC&lt;/th&gt;
     &lt;th&gt;infoD&lt;/th&gt;
    &lt;/tr&gt;
   &lt;thead&gt;
   &lt;tbody&gt;
    &lt;tr&gt;
     &lt;td&gt;
     &lt;input type="text asp-for="Shift0"&gt;
     &lt;/td&gt;
     &lt;td&gt;
     &lt;input type="text" asp-for="Date0" class="datepickerInput"/&gt;
     &lt;/td&gt;
     &lt;td&gt;
     &lt;input type="text" asp-for="Time0" class="timepickerInput" /&gt;
     &lt;/td&gt;
     &lt;td&gt;
     &lt;input type="text" asp-for="Day0" /&gt;
     &lt;/td&gt;
    &lt;/tr&gt;
    &lt;td&gt;
     &lt;input type="text asp-for="Shift1"&gt;
     &lt;/td&gt;
     &lt;td&gt;
     &lt;input type="text" asp-for="Date1" class="datepickerInput"/&gt;
     &lt;/td&gt;
     &lt;td&gt;
     &lt;input type="text" asp-for="Time1" class="timepickerInput" /&gt;
     &lt;/td&gt;
     &lt;td&gt;
     &lt;input type="text" asp-for="Day1" /&gt;
     &lt;/td&gt;
    &lt;tr&gt;
     @*..More of the same tds with different ids.*@
    &lt;/tr&gt;
   &lt;/body&gt;
  </code></pre>
  
  <p>I need the Id of Day based on the Id of Date in the same row.</p>