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.

3 Answers 3

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 ).

Sign up to request clarification or add additional context in comments.

Comments

1
var tr = $('#table_id tr:eq(1)');
tr.find("input[name=s_attr]").val();
tr.find.. etc...

2 Comments

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)
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)
1

Use the attribute selector and the .val() function

$('[name=s_attr]').val()
$('[name=p2]').val()
$('[name=id]').val()

3 Comments

Ok, thanks, but how can i use this with my row selector? $('#table_id tr').eq(1)??
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
the bad thing that i can have multiple input field: ( but thanks for your help... Anyway appreciate your help and upvoted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.