|
-
May 16th, 2012, 08:12 AM
#6
Re: How to use Javascript to get the value of a radio button
An option button is used to select a single value.
So, the "undefined" issue can be cleared using an if statement to check it and alert the user with a message. Like this:
Code:
$('#checker').click(function(){ // Whenever a radiobox is clicked, the following code would be executed
var selectedValue = $('input[name=Vehicle]:checked').val(); // get the selected radio box's value
if(selectedValue === undefined) //check if user had selected an option
{
alert('Please select an option to continue !');
}
else{
alert(selectedValue); // display it
}
});
(I have updated the fiddle)
Another option is to put a default selection in one of the option boxes.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|