-1

I need select value of radio, when I click on button.
This is my code. jquery code must start with this code:

$('.button').click(function(){});

I wrote this code but it not work:

$('.button').click(function(){
    var t = $(this).parent().find('td div#select_type').children('input[checked=checked]').html(); });

 <table>
        <tbody>
            <tr class="row">
                <td>1</td>
                <td>2</td>
                <td>3</td>
                <td>4</td>
                <td width="130">
                    <div id="select_type">
                        <input value="0" id="select_type_0" type="radio" name="select_type" />
                        <label for="select_type_0"></label>
                        <input value="1" id="select_type_1" type="radio" name="select_type" />
                        <label for="select_type_1"></label>
                        <input value="2" id="select_type_2" type="radio" name="select_type" checked=checked />
                        <label for="select_type_2"></label>
                    </div>
                </td>
                <td class="button button_bt" style=" border: none">
                    <a>button</a>
                </td>
            </tr>
            <tr>
            ...
            </tr>
        </tbody>
    </table>
ztirom
  • 4,292
  • 3
  • 27
  • 39
user2969404
  • 27
  • 2
  • 10
  • `.html` gets the content _inside_ an element (HTML code of child elements and text nodes) – `input` elements do not have any content “inside” of them. – CBroe Jan 18 '15 at 01:02
  • possible duplicate of [jQuery get value of selected radio button](http://stackoverflow.com/questions/8622336/jquery-get-value-of-selected-radio-button) – CBroe Jan 18 '15 at 01:02

3 Answers3

1

Here is the solution

var t = $(this).parent().find('td div#select_type').children('input:checked').val();alert(t);

Demo JSFiddle

Nadeemmnn Mohd
  • 713
  • 5
  • 14
0

I cant find your mistake, but I can offer other solution

First lets give id to elements

<table>
    <tbody>
        <tr class="row">
            <td>1</td>
            <td>2</td>
            <td>3</td>
            <td>4</td>
            <td id="form" width="130">
                <div id="select_type">
                    <input value="0" id="select_type_0" type="radio" name="select_type" />
                    <label for="select_type_0"></label>
                    <input value="1" id="select_type_1" type="radio" name="select_type" />
                    <label for="select_type_1"></label>
                    <input value="2" id="select_type_2" type="radio" name="select_type" checked=checked />
                    <label for="select_type_2"></label>
                </div>
            </td>
            <td id="btn" class="button button_bt" style=" border: none">
                <a>button</a>
            </td>
        </tr>
        <tr>
        ...
        </tr>
    </tbody>
</table>

than call jquery like this

$('.button').click(function(){
var t = $("#form input[type='radio']:checked").val();});

it will fork correctly

Gor
  • 2,600
  • 6
  • 22
  • 45
0

JS

$('.button > a').click(function(){
    var myValue= $('div#select_type input:radio:checked').val();
    alert(myValue);
});

also can find in fiddle

Lumi Lu
  • 3,271
  • 1
  • 10
  • 21