-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,382
  • 3
  • 28
  • 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

4 Answers4

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,808
  • 6
  • 25
  • 46
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,289
  • 1
  • 11
  • 21
0

"prop" worked for me:

$("#element_id").prop("checked", true);

My html:

<input type="radio" id="on_the_first" name="recurrence-monthly-option" value="on_the_first" checked="checked" />
<input type="radio" id="on_day_of_month" name="recurrence-monthly-option" value="on_day_of_month" />

I tried (but didn’t work):

$('input:radio[name=recurrence-monthly-option]:nth(0)').attr('checked', true);
$('input:radio[name=recurrence-monthly-option]:nth(1)').attr('checked', true);
$("#on_the_first").attr('checked', '');
mortenma71
  • 1,078
  • 2
  • 9
  • 27