Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
get radio input value in jQuery

How to get radio input value in jQuery ?

Aman Jain, October 31, 2021November 5, 2023

While submitting a form or validating a form using the jQuery, we can get all the values of form easily but radio button works differently and we need some extra efforts to fetch the value of radio input. So in this article i will demonstrate to fetch the value of radio button.

In this example i will use a question to select a radio button with 4 options.

beenhere

$(“input[name=’answer’]:checked”).val()

Get radio input value using name

In the example we will get the value using name attribute of input.

<!DOCTYPE html>
<html>
<head>
    <title>Get value of selected radio button with Jquery - Readerstacks.com</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
   
<input type="radio" name="answer" value="1"> 1
<input type="radio" name="answer" value="4"> 4
<input type="radio" name="answer"  value="7"> 7
<input type="radio" name="answer"   value="8"> 8

<button>Submit/button>
   
<script type="text/javascript">
   
    $("button").click(function(){
        var val = $("input[name='answer']:checked").val();
        alert(val);
    });
   
</script>
  
</body>
</html>

Get radio input value using class

In this example we will get the value using class and :checked

<!DOCTYPE html>
<html>
<head>
    <title>Get value of selected radio button with Jquery - Readerstacks.com</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
   
<input type="radio" class='answer_radio' name="answer" value="1"> 1
<input type="radio" class='answer_radio' name="answer" value="4"> 4
<input type="radio" class='answer_radio' name="answer"  value="7"> 7
<input type="radio" class='answer_radio' name="answer"   value="8"> 8

<button>Submit/button>
   
<script type="text/javascript">
   
    $("button").click(function(){
        var val = $(".answer_radio:checked").val();
        alert(val);
    });
   
</script>
  
</body>
</html>

Related

Javascript jQuery HTMLJavascriptjquery

Post navigation

Previous post
Next post

Related Posts

Javascript How to Insert script tag dynamically in html in angular

How to Insert script tag dynamically in angular ?

March 24, 2022August 4, 2022

Sometimes we want to insert script tag in angular app, For an instance we have third party APIs or widget and we wanted to add it in our page then in this condition provided script are not angular friendly or we can say it can be pure JavaScript. so to…

Read More

Show dropdown list from ajax response in jQuery

September 10, 2021September 10, 2021

Showing Dynamic Select Box using jQuery and Php,MySql In this tutorial, we are going to learn the dropdown list using AJAX. Loading dropdown values from AJAX requires knowledge of javascript, jQuery, php and html. Sometimes it requires to load the dropdown like countries, state, city list dependently. In this case…

Read More
Javascript Angular Keypress Enter Event on Input Example

Angular Keypress Enter Event on Input Example ?

September 21, 2022March 16, 2024

Input events in angular can be handled using input and output decorators and in this tutorial we will learn Angular Keypress Enter Event on Input with Example. In core javascript we use onkeypress event to handle the key events of input but in angular it there is different way to…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • The Transformative Power of Education in the Digital Age
  • Understanding High Vulnerabilities: A Closer Look at the Week of July 14, 2025
  • Exploring Fresh Resources for Web Designers and Developers
  • The Intersection of Security and Technology: Understanding Vulnerabilities
  • Mapping Together: The Vibrant Spirit of OpenStreetMap Japan
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version