I would suggest making all of these items related via numeric IDs, you then
dispose with having to traverse up and back down the DOM to find the related
elements:

<tr>
 <td>
   <select id="select_1">...</select>
 </td>
 <td>
   <input id="text_1a" type="text" ... />
 </td>
 <td>
   <input id="text_1b" type="text" ... />
 </td>
 <td>
   <input id="text_1c" type="text" ... />
 </td>
 <td>
   ...
 </td>
</tr>


// Update 2nd column <input> with new_value.
// $(this) is the select in the first row cell.
var index = /select_(\d+)/.exec(this.id)[1];  // Get the number from the
ID. There is no checking if it doesn't match.
var new_value = $(this).val();
$("text_"+index+"a").val(new_value);


Incidentally, as I've used here, the .val() function is a handy shortcut for
.attr("val", ...)

I don't know what the speed difference is here but I'm guessing it'll be
pretty good.

HTH,
--rob


On 6/21/07, Brad Perkins <[EMAIL PROTECTED]> wrote:


Imagine a table row like this

<tr>
  <td>
    <select>...</select>
  </td>
  <td>
    <input type="text" ... />
  </td>
  <td>
    <input type="text" ... />
  </td>
  <td>
    <input type="text" ... />
  </td>
  <td>
    ...
  </td>
</tr>



Depending on the select option I need to modify or clear values in the
text inputs in the 2nd, 3rd, and 4th cells.

I find that this code works, but suspect there may be a better way to
achieve the same result with less code?

// Update 2nd column <input> with new_value.
// $(this) is the select in the first row cell.
$

(this).parent('td').parent('tr').children('td').eq(1)children('input').attr("value",new_value);

Since I'll be updating various cells I suppose this helps, but again
suspect there is a better way.
var cells = $(this).parent('td').parent('tr').children('td');
cells.eq(1).children('input').attr("value",new_value_1);
cells.eq(3).children('input').attr("value",new_value_2);
cells.eq(4).children('input').attr("value",new_value_3);

Thanks

Brad




--
Rob Desbois
Eml: [EMAIL PROTECTED]
Tel: 01452 760631
Mob: 07946 705987
"There's a whale there's a whale there's a whale fish" he cried, and the
whale was in full view.
...Then ooh welcome. Ahhh. Ooh mug welcome.

Reply via email to