tobiak777
tobiak777

Reputation: 3365

Value of input field not retrieved : undefined object

I have the following HTML :

<table>
... some other rows
<tr>
   <td>
      <input id="Products_0__Quantity" class="product-quantity" type="text" />
  </td>
  <td>
     ...Some other columns
  </td>
</tr>
... some other rows
</table>

I have attached an event handler to a link contained in every row. I know it works,because other parts of the event handler function simply work fine. However this part doesn't :

var tr = $(this).closest('tr');
var productQuantity = tr.children('input.product-quantity').val();

After this line, productQuantity is still undefined.

What's the problem ?

Upvotes: 1

Views: 82

Answers (3)

user4595940
user4595940

Reputation:

Please Try this:-

tr.find('input.product-quantity').val();

Instead of Children

Upvotes: 1

Carlo G.
Carlo G.

Reputation: 152

In my opinion something gone wrong in the definition of $(this), are you sure about the element you get with $(this)?

however the .find() is better than children.

Upvotes: 0

Satpal
Satpal

Reputation: 133453

Use .find() instead of .children()

The .children() method differs from .find() in that .children() only travels a single level down the DOM tree while .find() can traverse down multiple levels to select descendant elements (grandchildren, etc.) as well.

Code

tr.find('input.product-quantity').val()

Upvotes: 4

Related Questions