0

I am stuck with complicated html structure. And also can't change it as it is come from server side(outside).

I am trying to get input radio selected value. But can't.

Following what i have tried But, as i am not much powerful can't solution. And also don't know what i am trying is right Or Wrong.

As there is multiple elements i have tried with children And also there are other radio inputs in my html markup.

console.log($('.ClearanceItem')[0].rows[0].cells[1].children[0].children[1].children[0].children[1].children.find('input[name="myRadio"]:checked').val());
<table>
  <tbody class="ClearanceItem">
    <tr>
      <td>
        <table>
          <tbody>
            <tr>
              <td>
                <label>
                  <input type="radio" checked="checked" value="1" name="Mobile">Clear
                </label>
                <label>
                  <input type="radio" value="2" name="Mobile">Pending
                </label>
                <label>
                  <input type="radio" value="3" name="Mobile">Waived Off
                </label>
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr>
      <td>
        <table>
          <tbody>
            <tr>
              <td>
                <label>
                  <input type="radio" value="1" name="Computer">text1
                </label>
                <label>
                  <input type="radio" checked="checked" value="2" name="Computer">text2
                </label>
                <label>
                  <input type="radio" value="3" name="Computer">text3
                </label>
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>

  </tbody>

</table>

Any help would greatly appreciated.

ketan
  • 19,129
  • 42
  • 60
  • 98

1 Answers1

3

$('input[name=radioName]:checked').val() will return the selected radio.

You can also specify which form the radio is a child of by using the following example:

$('input[name=radioName]:checked', '#myForm').val()
Ari Seyhun
  • 11,506
  • 16
  • 62
  • 109
  • first line is ok. simply change 'radioName' to the real name of your input - Mobile/Computer – Tal Apr 02 '16 at 07:43
  • Second line is not relevant if your radio buttons have different names. you could use it though if you wrap both in different forms giving each its own id and change 'myForm' to the desired form id – Tal Apr 02 '16 at 07:46