3

On my webpage, I have a button whose click dynamically generates a table. Each row of the table has a radio button. Now, I am trying to get the checked radio button nearest td value.. I mean the amount value..

<table cellpadding="0" cellspacing="0" width="100%" class="table table-bordered table-striped ">
    <thead>
        <tr>
            <th>
                <div class="checker"><span><input type="checkbox" class="checkall"></span>
                </div>
            </th>
            <th>Amount</th>
            <th>Agg Starts</th>
            <th>Agg Ends</th>
            <th>Next Renewal</th>
            <th>Term</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <div class="checker"><span class=""><input type="checkbox" name="checkbox" class="ads_Checkbox" value="2"></span>
                </div>
            </td>
            <td><a class="show_hide1" href="" id="ah">1200000</a>
            </td>
            <td>15-01-2013</td>
            <td>31-12-2013</td>
            <td>01-01-2014</td>
            <td>1</td>
        </tr>
        <tr>
            <td>
                <div class="checker"><span class="checked"><input type="checkbox" name="checkbox" class="ads_Checkbox" value="65"></span>
                </div>
            </td>
            <td><a href="" id="ah">200</a>
            </td>
            <td>19-11-2013</td>
            <td>19-11-2013</td>
            <td>24-11-2013</td>
            <td>2</td>
        </tr>
    </tbody>
</table>
Dhanush Bala
  • 1,122
  • 1
  • 14
  • 27
  • use a id for each and every radio buttons and reffer this [link][1]. [1]: http://stackoverflow.com/questions/4813219/jquery-checkbox-value – Lakmal Vithanage Nov 20 '13 at 10:54
  • hi if i click the check box, how i get the amount value (nearest td) – Dhanush Bala Nov 20 '13 at 10:59
  • The question is not clear.I think you are trying to click a check box and get the value to a text box. is it ? – Lakmal Vithanage Nov 20 '13 at 11:01
  • you meant, if you check first one it means 1200000 ? – Lakmal Vithanage Nov 20 '13 at 11:07
  • ok. you have a seperate button. then you check a ckeck box and after click the button you need to get the value. is it ? – Lakmal Vithanage Nov 20 '13 at 11:10
  • i have a common button , i dont need button in each row.. – Dhanush Bala Nov 20 '13 at 11:11
  • ok. you use a php code to generate the table. when generating table you can dinamically assign ids for every tds. then in check box id may c1, c2 , c3.... and tds with values may be vc1 , vc2 , vc3. vc1 is related to v1 accordingly. then write a code to the button(javascript) to get checked checkboxe's ids and you can get the values from vcx(x can be 1,2,3...) – Lakmal Vithanage Nov 20 '13 at 11:17

1 Answers1

3

Your question is not clear. But, after reading the comments, I think this is what you need.

$(".checker input").change(function(){
    if(this.checked){
        var value = $(this).closest("tr").find("td:eq(1)").find("a").text();
        alert(value);
    }

});

You can try it here.

http://jsfiddle.net/augusto1982/XPLx7/

Note: Using the closest method is a neat way of avoiding parent().parent()...parent() in your code.

Augusto
  • 779
  • 5
  • 18