How can I know which radio button is selected via jQuery?
To get the value of the selected radioName
item of a form with id myForm
:
$('input[name=radioName]:checked', '#myForm').val()
Here's an example:
$('#myForm input').on('change', function() {
alert($('input[name=radioName]:checked', '#myForm').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myForm">
<fieldset>
<legend>Choose radioName</legend>
<label><input type="radio" name="radioName" value="1" /> 1</label> <br />
<label><input type="radio" name="radioName" value="2" /> 2</label> <br />
<label><input type="radio" name="radioName" value="3" /> 3</label> <br />
</fieldset>
</form>
How to check a radio button with jQuery?
For versions of jQuery equal or above (>=) 1.6, use:
$("#radio_1").prop("checked", true);
For versions prior to (<) 1.6, use:
$("#radio_1").attr('checked', 'checked');
Tip: You may also want to call click()
or change()
on the radio button afterwards. See comments for more info.
How to know which radio button is selected in jquery?
var selectedValue = $("input[name=form]:checked").val();
How to check radio button is checked using JQuery?
Given a group of radio buttons:
<input type="radio" id="radio1" name="radioGroup" value="1">
<input type="radio" id="radio2" name="radioGroup" value="2">
You can test whether a specific one is checked using jQuery as follows:
if ($("#radio1").prop("checked")) {
// do something
}
// OR
if ($("#radio1").is(":checked")) {
// do something
}
// OR if you don't have ids set you can go by group name and value
// (basically you need a selector that lets you specify the particular input)
if ($("input[name='radioGroup'][value='1']").prop("checked"))
You can get the value of the currently checked one in the group as follows:
$("input[name='radioGroup']:checked").val()
How to get value of selected radio button?
var rates = document.getElementById('rates').value;
The rates element is a div
, so it won't have a value. This is probably where the undefined
is coming from.
The checked
property will tell you whether the element is selected:
if (document.getElementById('r1').checked) {
rate_value = document.getElementById('r1').value;
}
Or
$("input[type='radio'][name='rate']:checked").val();
Find out whether radio button is checked with JQuery?
$('#element').click(function() {
if($('#radio_button').is(':checked')) { alert("it's checked"); }
});
jQuery Check if a Radio Button is Selected or not
Try this:
// Table: Add class row selected
$('.table tbody :radio').change(function() {
$('.table tbody :radio:checked').closest('tr').addClass('selected-row');
$('.table tbody :radio:not(:checked)').closest('tr').removeClass('selected-row');
});
How can I check which of the two radio button is checked in javascript/jquery?
use attribute selector along with :checked selector and .val() to get the value of the checked input element with name AS88
$('input[name="AS88"]:checked').val()
Demo: Fiddle
Determine if radio buttons are checked using jQuery
Your problem is because $(this)
is referring to the textbox and not the rowID.
To fix do this:
$("#rowID input[type=text]").blur(function () {
var checkedRadios = $('#rowID').find('input:radio:checked');
if (checkedRadios.length > 0) {
alert("yes");
} else {
alert("no");
}
});
Related Topics
How to Prevent Buttons from Submitting Forms
Reading File Contents on the Client-Side in JavaScript in Various Browsers
Jquery Load() Only Working in Firefox
How to Properly Use Jspdf Library
Why Does Forms With Single Input Field Submit Upon Pressing Enter Key in Input
How Might I Get the Script Filename from Within That Script
Does Html5 Allow Drag-Drop Upload of Folders or a Folder Tree
Jquery Mobile: Document Ready Vs. Page Events
How to Write Data to File Using Only JavaScript
How to Check File Mime Type With JavaScript Before Upload
Hide Text in HTML Which Does Not Have Any HTML Tags
How to Calculate the Number of Days Between Two Dates
How to Scroll to an Element Inside a Div