Shinu Thomas
Shinu Thomas

Reputation: 5316

How to get the value of a textbox inside a <td> using the id of <tr> in jquery

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

Answers (6)

carlos
carlos

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

Alessandro Minoccheri
Alessandro Minoccheri

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

Guffa
Guffa

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

Rusty
Rusty

Reputation: 1303

You can use:

$('table tr input').val()


$('#2 input').val()

Upvotes: 0

codingbiz
codingbiz

Reputation: 26386

You can try

$('#1 input[type="text"]').val();

Upvotes: 0

iappwebdev
iappwebdev

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

Related Questions