0

Hello i have a table with Data attribute and i what to find if the data attribute has the same value.

 <tr style="height: 40px;" cart-item="" data-line-weight="10" data-total-lien="10" data-item-barcode="3434" class="tablerow" id="rowid1">

I am trying to find the TR that has data-item-barcode is equal "3434" and change the value of the input filed that is inside the TR that was found

<tr style="height: 40px;" cart-item="" data-line-weight="10" data-total-lien="10" data-item-barcode="3434" class="tablerow" id="rowid1">
<td width="210" class="text-left" style="line-height:30px;">
<span style="text-transform: uppercase;">food</span></td>
<td width="130" class="text-center" style="line-height:30px;">10</td>
<td width="145" class="text-center"><div class="input-group input-group-sm">
<span class="input-group-btn">
<button class="btn btn-default item-reduce" type="button" id="reduce1">-</button>
</span>
<input type="number" name="QNY[]" value="1" class="form-control qny" aria-describedby="sizing-addon3" id="qny1">
<span class="input-group-btn"><button class="btn btn-default item-add" type="button" id="addB1">+</button></span></div></td></tr>

Thanks

2
  • 1
    Question is not clear ...can you please clarify what exactly you are looking at Commented Oct 29, 2016 at 21:13
  • Edit Then query Commented Oct 29, 2016 at 21:23

2 Answers 2

1

If I understand well what you'd like to achieve this should work:

$('tr[data-item-barcode="3434"] input[type="number"]').val('YOUR VALUE');
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not quite sure what are you trying to achieve but I guess it goes like this, if I matched tr with that attribute (data-item-barcode=3434) I want to update input with some value?

So, here it goes:

var trMatched = $("tr[data-item-barcode=3434]");
if(trMatched.length > 0){
  $("input", trMatched).val(20);
  }
<!DOCTYPE html>
<html>

<head>
  <title>Test</title>
</head>

<body>
  <table>
  <tr style="height: 40px;" cart-item="" data-line-weight="10" data-total-lien="10" data-item-barcode="3434" class="tablerow" id="rowid1">
    <td width="210" class="text-left" style="line-height:30px;">
      <span style="text-transform: uppercase;">food</span>
    </td>
    <td width="130" class="text-center" style="line-height:30px;">10</td>
    <td width="145" class="text-center">
      <div class="input-group input-group-sm">
        <span class="input-group-btn">
<button class="btn btn-default item-reduce" type="button" id="reduce1">-</button>
</span>
        <input type="number" name="QNY[]" value="1" class="form-control qny" aria-describedby="sizing-addon3" id="qny1">
        <span class="input-group-btn"><button class="btn btn-default item-add" type="button" id="addB1">+</button></span>
      </div>
    </td>
  </tr>
</table>

</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

</html>

Comments

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.