Reputation: 5316
i have a table like this
<table>
<tr id ='1tr'>
<td><input type='textbox' value='1'></td>
<td><input type='textbox' value='2'></td>
</tr>
<tr id ='2tr'>
<td><input type='textbox' value='3'></td>
<td><input type='textbox' value='4'></td>
</tr>
</table>
how i can get the value of text box in second td that is in tr with id 2tr
Upvotes: 3
Views: 16800
Reputation: 11
I think that you can use this way.
Here i'm have acces to each txttexboxname and get the value
$("#tablename input[name='txttexboxname']").each(function(indice){
alert($(this).val()) //show the value
alert($("#tablename [id='txttexboxname']:eq("+(index)+")").val()) //show the value
}
Upvotes: 0
Reputation: 35973
Try this code:
$('#1 input').val();
New code after your edit in your answer
$('#2tr td:eq(1) input').val();
is what you want?
Upvotes: 6
Reputation: 700382
That would be:
$('#2 input').val()
If your code is more complex than your example, you may need to make the selector more specific, for example:
$('#2 > td > input[type=text]').val()
Note that you should avoid using numbers as id. That causes problems in some situations.
Also note that the type should be text
, not textbox
:
<input type='text' value='1'>
Upvotes: 0
Reputation: 5910
There is no textbox in tr with id '1', so I guess you wnat this one out of tr with id '2'...
You can write:
$('#2 td input').val()
But it is not recommended to use number as ID in an HTML-DOM!
Upvotes: 1