1

Given a table with a plenty of row like this:

<tr>
<td><input class="szoveg" type=text name=p1 maxlength=2 size=2 value="7"></td>
<td><select class="szoveg" name=p2><option value=1 selected>Live<option value=2>Teszt</select></td>
<td><input class="gomb" type=submit value=Modify></td>
<td><input type=hidden name=s_attr value=s_value></td>
<td><input type=hidden name=m_attr value=m_value></td>
<td><input type=hidden name=id value="AAAR7u"></td>
<td><input class="btn" value=Del></td>
</tr>

I would like to get:

  • s_value of the s_attr
  • Éles of the p2 select input type
  • AAR7u of the id

and so on, I need almost each of the values inside the <td> tags, I want to give as an argument and invoke a function with it...

How can I achieve getting with jQuery?

Now I can get the row only with this jQuery selector:

$('#table_id tr').eq(1)

But I need also the values.... Every help is appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
czupe
  • 4,740
  • 7
  • 34
  • 52

3 Answers3

2

$("#table_id tr").eq(1).find("td").eq(3).find("input").val() gives you the value of the input in row 1 column 3 of your table ( or whatever row and column number you enter ).

William Smith
  • 573
  • 1
  • 5
  • 11
1

Use the attribute selector and the .val() function

$('[name=s_attr]').val()
$('[name=p2]').val()
$('[name=id]').val()
Stephen Sorensen
  • 11,455
  • 13
  • 33
  • 46
  • Ok, thanks, but how can i use this with my row selector? $('#table_id tr').eq(1)?? – czupe Jun 26 '13 at 14:25
  • Do you just want the value of whatever input field is in a specific table row? If so you can do $('#table_id tr:eq(1) :input').val(), which will give you the value of the input field in the first row. This of course assumes that you only have one input field in each row – Stephen Sorensen Jun 26 '13 at 14:34
  • the bad thing that i can have multiple input field: ( but thanks for your help... Anyway appreciate your help and upvoted – czupe Jun 26 '13 at 14:38
1
var tr = $('#table_id tr:eq(1)');
tr.find("input[name=s_attr]").val();
tr.find.. etc...
reyaner
  • 2,799
  • 1
  • 12
  • 17
  • ok, but this will do it for all of the rows, and i need only e.g. the second or third row... So e.g. how can i use this with that? $('#table_id tr').eq(1) – czupe Jun 26 '13 at 14:26
  • OK, thank you man, seems fine! You have any knowledge of a 'one liner' solution? or only this?:) (i will upvate instantly after your answer not related to the content of the answer) thanks! Or maybe easier solution? (not find) – czupe Jun 26 '13 at 14:36