Aldi Unanto
Aldi Unanto

Reputation: 3682

Get particular value for each <input>

So this is the case.

I have 2 <input> inside <td> which has unlimited number. For example :

<td>
   <input type="text" name="cust_name" onchange="check(this)" />
   <input type="hidden" name="cust_id" value="10" />
</td>
<td>
   <input type="text" name="cust_name" onchange="check(this)" />
   <input type="hidden" name="cust_id" value="12" />
</td>
......

this in check(this) containing cust_name value. But how can I get particular cust_id value with same function? (check())

Delineation :

function check(part_element){
   console.log($(part_element).val());
   console.log(getting particular cust_id value); //here is the part
}

Upvotes: 0

Views: 82

Answers (3)

Evan Trimboli
Evan Trimboli

Reputation: 30082

This already has an accepted answer, but in this case I'd argue that using jQuery doesn't make this any easier, possibly even more complicated:

function check(el) {
    console.log(el.value);
    console.log(el.nextSibling.value);
}

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

you can use .next() to find the next sibling, in this case it is the cust_id element

function check(part_element){
   console.log($(part_element).val());
   console.log($(part_element).next().val()); //here is the part
}

Upvotes: 1

Musa
Musa

Reputation: 97672

You can use next

function check(part_element){
   console.log($(part_element).val());
   console.log($(part_element).next().val()); 
}

Upvotes: 1

Related Questions