I have the following HTML:
<tr class="wiring_details_6-48">
<td colspan="2"> Wire Type:
<select name="select_wire_6" onchange="Estimate.select_wire( 6, this.value, 0 );">
<option value="" selected="">Select wire..</option>
<option value="1">14/2</option>
<option value="2">14/4</option>
<option value="3">16/4</option>
<option value="4">16/2</option>
<option value="5">RG6</option>
<option value="6">CAT5</option>
<option value="7">RG59</option>
<option value="8">LVT</option>
<option value="9">CAT6</option>
<option value="10">HDMI</option>
<option value="11">Shielded CAT6</option>
</select> </td>
<td colspan="2">Length:
<input type="text" class="id_wire_length_6" name="wire_length_6" value="0"></td>
<td colspan="2">Retail Price:
<input type="text" class="id_wire_retail_6" name="wire_retail_6" value="0"> </td>
<td colspan="2">
<input type="hidden" id="wire_id_6" name="wire_id_6" value="0"> </td>
</tr>
I want to make sure that input – id_wire_length and id_wire_retail are related to their parent tr this can be proven due to the part-id which is in this example the number 6 in wiring_details and in id_wire_length and id_wire_retail.
The JS that I have is:
$('input[class^="id_wire_retail"]').each(function() {
parts_cents_total += (Money.dollars_to_cents($(this).val()) * $('input[class^="id_wire_length"]').val());
});
The above matches the id_wire_detail part as well as the id_wire_length – but how do I make sure that it is the one related to its parent,
So I guess it comes down to this:
How do I get the parent tr‘s part number (6) and then make sure that the above JS matches only input elements with the tr‘s part number in them?
Instead of this:
…try this:
This will ensure that the value you’re selecting is the one “inside” the same
<tr>. Assuming the HTML structure is as you’ve posted above, you shouldn’t have to worry about matching by part number.