0

Writing a HTML code, where by successful submission, i want to check the value which i have selected. Unable to see that value which i have selected in the radio button.

*

    <input name="ec" class="g" type="radio" value="E" disabled="'disabled'" checked="checked">
        E
        <br>*

What should i do to fix the issue?

4 Answers4

0

You cant get disabled values on your post actions. Just don't make the radio button disabled and it will get the value if it's checked, or you can make it ReadOnly like that: <input name="ec" class="g" type="radio" value="E" readonly="readonly" checked="checked">

Take a look at this StackOverflow answer

Community
  • 1
  • 1
Dr. Roggia
  • 1,095
  • 3
  • 16
  • 40
0

You can get it like the following snippet with jquery

alert($('input[name=ec]:checked').val())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="ec" class="g" type="radio" value="E" disabled="'disabled'" checked="checked">
        E
        <br>*
Afnan Ahmad
  • 2,492
  • 4
  • 24
  • 44
  • Have you got any Links to check how to debug in Chrome without breakpoints if i don't know which javascript file I am using? –  Feb 21 '17 at 09:20
  • If you want to use the above snippet. You need to add `jQuery` as I did in above snippet. – Afnan Ahmad Feb 21 '17 at 10:21
0

its works fine as @Afnan says. but when you have multiple radio and you need all selected radio button value then you need to do this

    var radio= [];
    $.each($("input[name='sport']:checked"), function(){            
        favorite.push($(this).val());
    });
    alert("My selected checkbox  are: " + favorite.join(", "));

and yaah forget to tell you need to add script file as ..

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Kishan Oza
  • 1,707
  • 1
  • 16
  • 38
0

Vanilla JavaScript

If you want to show value of radio button when radio is checked, then just write

if (document.getElementById('s').checked) { 
   selectedVal = document.getElementById('s').value; 
}

if (document.getElementById('s').checked) {
  selectedVal = document.getElementById('s').value;
}
alert(selectedVal);
<input name="ec" class="g" type="radio" id="s" value="E" disabled="'disabled'" checked="checked"> E
<br>*
Hidayt Rahman
  • 2,490
  • 26
  • 32