Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home Javascript JQuery Get selected value of radio button

JQuery Get selected value of radio button

This article shows you the way of getting selected value of radio button in JQuery which is JavaScript library helps us write less, do more.
 
Before approach this method, please take a look about the way how to get selected value of radio button using JavaScript posted by Mr Hoan with the title : JavaScript Get Radio Button Value

In this article, we do the similar example with Hoan’s article.
 

1. Design list of radio buttons in HTML as below

<form id="myForm" runat="server">
    <div id="divSport">
       <input id="rdoSport1" type="radio" name="Sport" value="Football" /> Football
       <input id="rdoSport2" type="radio" name="Sport" value="Tennis" /> Tennis
       <input id="rdoSport3" type="radio" name="Sport" value="Volleyball" /> Volleyball
    </div>
    <input type="button" id="btnSubmit" value="Submit"/>
</form>

<form id="myForm" runat="server"> <div id="divSport"> <input id="rdoSport1" type="radio" name="Sport" value="Football" /> Football <input id="rdoSport2" type="radio" name="Sport" value="Tennis" /> Tennis <input id="rdoSport3" type="radio" name="Sport" value="Volleyball" /> Volleyball </div> <input type="button" id="btnSubmit" value="Submit"/> </form>

2. Using JQuery to get selected value of radio button

 <script language="javascript">
     $(document).ready(function() {
     $("#btnSubmit").click(function() {                 
             var selected = $("#divSport input[type='radio']:checked");
             if (selected != "undefined" && selected.length > 0) {
                 selectedValue = selected.val();
                 alert("Selected value : " + selectedValue);
             }
             else {
                 alert("Please select a kind of sport!");
             }
         });
     });                  
 </script>

<script language="javascript"> $(document).ready(function() { $("#btnSubmit").click(function() { var selected = $("#divSport input[type='radio']:checked"); if (selected != "undefined" && selected.length > 0) { selectedValue = selected.val(); alert("Selected value : " + selectedValue); } else { alert("Please select a kind of sport!"); } }); }); </script>

3. The key point of this method is this code line:

       $("input[name='radioname']:checked").val();

$("input[name='radioname']:checked").val();

[download id=”2″ format=”1″]
Feb 14, 2012quynhnguyen
Capture WebPage Right On Google ChromePHP Get Remote Image Width Height
You Might Also Like:
  • JavaScript Get Radio Button Value
  • Get Image Width Height With JQuery And JavaScript
  • JQuery How to use DatePicker
  • Jquery checkbox checked
  • ASP.NET JQuery Autocomplete Textbox
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • Javascript Problem Set focus textbox on Firefox
  • JQuery Dialog Hide Or Remove Close Button
  • How To Track Website With Multiple Google Analytisc Accounts
  • JQuery Allow only numeric characters or only alphabet characters in textbox
quynhnguyen
10 years ago JavascriptJavaScript, JQuery315
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
24,444 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
21,824 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
17,638 views
JQuery Allow only numeric characters or only alphabet characters in textbox
14,982 views
C# Read Json From URL And Parse/Deserialize Json
11,694 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Things to Learn about Installingderm Loan Type S
  • Online Photo Editor – Free Photoediting Software
  • A Guide to Finding the Best Paper Sellers
  • Photoediting in Home Isn’t Hard to Do!

  • Free Photo Editor Online
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (27)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (647)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development