How to get the value from a radio button in HTML?

January 18th, 2010 | by admin |

It’s easy to make a radio button and assigning a value to it. It’s probably really dumb, but somehow I can’t seem to figure out how to display that value again. Any instructions of how to do that for somebody with only a very basic idea of HTML (I am trying to learn it…)?

You can get the value of an HTML radio button by using simple client-side javascript.

Example:
In between your <head> tags place the following code…

<script lang="javascript" type="text/javascript">
<!–
function GetRadioButtonValue()
{
var Value = document.getElementById("myRadioButton").getAttribute("value");
alert(Value);
}
–>
</script>

In between your body tags place the following code…

<input type="radio" value="hello" id="myRadioButton" />
<input type="button" value="Click Me" onClick="GetRadioButtonValue();" />

  1. 4 Responses to “How to get the value from a radio button in HTML?”

  2. By musicjunkie on Jan 19, 2010 | Reply

    Here’s the code if that’s what you’re asking:
    <p><input type="radio" value="insert value here" name="insert name here">insert text here</p>
    References :

  3. By harryronhermy on Jan 19, 2010 | Reply

    For that you need to know server side programming languages like ASP, ASP.NET, CGI or PHP or atleast Java Script. ASP is fairly easy- runs on Windows Server.
    References :

  4. By alexjewell@sbcglobal.net on Jan 19, 2010 | Reply

    Go with PHP.
    Get out, "PHP 5 for Dummies" by Janet Valade, it helped me a lot: http://www.dummies.com/WileyCDA/DummiesTitle/productCd-0764541668,subcat-PROGRAMMING.html
    References :

  5. By Amit M on Jan 19, 2010 | Reply

    You can get the value of an HTML radio button by using simple client-side javascript.

    Example:
    In between your <head> tags place the following code…

    <script lang="javascript" type="text/javascript">
    <!–
    function GetRadioButtonValue()
    {
    var Value = document.getElementById("myRadioButton").getAttribute("value");
    alert(Value);
    }
    –>
    </script>

    In between your body tags place the following code…

    <input type="radio" value="hello" id="myRadioButton" />
    <input type="button" value="Click Me" onClick="GetRadioButtonValue();" />
    References :

Post a Comment