Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML child selector with predefined parameter

I have a function where input element triggers ng-blur method with $event parameter:

$scope.MarkField = function(event)
{
}

<tr>
     <td><input type="text" value="1" id="inputQuantity" ng-blur="MarkField($event);"></td>
     <td><input type="text" value="1" id="inputBruto"></td>
     <td><input type="text" value="1" id="inputNeto"></td>
</tr>

What I need to do is find values of other two inputs (inputBruto and inputNeto) in this row when ng-blur is clicked. How to do this?

EDIT:

I am passing $event parameter because I know I can do something like this:

$(event.target).parent().parent() - the row where all three inputs are.

But I don't know how to use this row later to get input by id.

It would be nice if something like this is possible:

$("#rowID > td > input[id=inputBruto]");

EDIT:

I've managed to find / change input[id=inputBruto] with:

$(event.currentTarget).parent().parent().find("input[id=inputBruto]").val("test")

Problem solved, thanks for help!

like image 814
FrenkyB Avatar asked Mar 09 '26 23:03

FrenkyB


2 Answers

You can try this,

$scope.MarkField = function($event)
{
    /* to get tr element */
    var parent = $event.currentTarget.parent().parent()
    var idCurrent = $event.target.id;
    /*from parent finding for #inputBruto & #inputNeto */
    var secInput=parent.querySelector("#inputBruto").value;
    var thirdInput=parent.querySelector("#inputNeto").value;
}
like image 54
Hemakumar Avatar answered Mar 11 '26 11:03

Hemakumar


Try this, find parent of the clicked element and find in that your id elements

$scope.MarkField = function($event)
{
 var parent=$event.target.parent();
 var secInput=parent.find("#inputBruto").val();
 var thirdInput=parent.find("#inputNeto").val();
 }
like image 41
ScanQR Avatar answered Mar 11 '26 13:03

ScanQR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!