tags:

views:

28

answers:

2

I am trying to change the value of only the very next select box after the current field.

The form is a long list of rows with fields that have the same classes. On focus of the "quantity" field in "row 1" I want to change the "type" select box to "boxes" in that same row. All the code I try makes ALL of the "type" select boxes on the entire page change. I only want the most immediate one, closest to the quantity field to change.

The UOM field is the field I am attempting to change when the user focuses on Quantity.

Thanks!

<tr class="draggable odd">
<td class="content-multigroup-cell-field-part-num">
    <div id="edit-group-order-0-field-part-num-value-wrapper" class="form-item">
        <label for="edit-group-order-0-field-part-num-value">J&amp;B No.: 
        </label>
        <input type="text" class="form-text text idleField" value="" size="10" id="edit-group-order-0-field-part-num-value" name="group_order[0][field_part_num][value]" pattern="[0-9]*">
    </div>
</td>
<td class="content-multigroup-cell-field-quantity">
    <div id="edit-group-order-0-field-quantity-value-wrapper" class="form-item">
        <label for="edit-group-order-0-field-quantity-value">Quantity: 
        </label>
        <input type="text" class="form-text text idleField" value="" size="5" id="edit-group-order-0-field-quantity-value" name="group_order[0][field_quantity][value]" pattern="[0-9]*">
    </div>
</td>
<td class="content-multigroup-cell-field-quantity-type">
    <div id="edit-group-order-0-field-quantity-type-value-wrapper" class="form-item">
        <label for="edit-group-order-0-field-quantity-type-value">UOM: 
        </label>
        <select id="edit-group-order-0-field-quantity-type-value" class="form-select" name="group_order[0][field_quantity_type][value]">
            <option selected="selected" value="">- None -
            </option>
            <option value="Box(es)">Box(es)
            </option>
            <option value="Case(s)">Case(s)
            </option>
            <option value="Each">Each
            </option>
            <option value="Feet">Feet
            </option>
        </select>
    </div>
</td>

J&B No.: Quantity: UOM: - None - Box(es) Case(s) Each Feet

A: 

Have you tried closest?

Rodrigo
Yes, but I am not sure I if I am doing it correctly.
Ryan
A: 

I am assuming that you are using table markup and are inside a focus event of an element inside a td.

$('input.quantity').focus( function() {
    //get current cell, find nearest select.type in the following siblings
    $(this).parent()
           .nextAll()
           .find('select.type:first').val('boxes');

});
redsquare
I got this to work by adding another "parent()"! Thank you!
Ryan