views:

51

answers:

1

this piece of code will loop for several time; When any user select any of the radio button I want to find which radio button is selected; With the selected index i want to get address_ object; now i want to access its siblings div values like addressLine_1, addressLine_2, addressLine_3, city, state, zip in a variable.

Please help to me write this piece of Jqery script.

<div class="address">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td width="8%" align="center"><input type="radio" name="addressSelected"  value="1" /></td>
        <td class="address_0" width="92%">
            <div class="addressLine_1">gotomedia LLC</div>
            <div class="addressLine_2">2169 FOLSOM ST</div>
            <div class="addressLine_3">STE M301</div>
            <div class="city floatLeft">SAN FRANCISCO</div>
            <div class="state floatLeft">&nbsp;CA</div>
            <div class="zip floatLeft">&nbsp;94110</div>
        </td>
    </tr>
    </table>
</div>
+1  A: 

I guess this would be your solution. You have to watch out for the value of the input field as this code checks $(this).val() == "1". Maybe you have to modify it.

var values = [];
$("input[name=addressSelected]:checked")
  .filter( function () { return $(this).val() == "1"  } )
  .parent()           // the parent td
  .siblings()         // the other tds
  .children("div")    // the divs
  .each( function () { values.push ( $(this).text ) } );

That should do the trick

You might change the each line:

 .each( function () { values[ this.className ] = $(this).text } );

so you can access it like: values['addressLine_1'] however you would have to remove your float classes for a good result

Ghommey