Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3307732
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:26:25+00:00 2026-05-17T21:26:25+00:00

In the script below, how do I get the values of only radio buttons

  • 0

In the script below, how do I get the values of only radio buttons and checkboxes that have been selected and not all (provided a radio button and checkbox were selected).

Right now it gives me the values of all, whether selected or not, and also the submit button (which i dont need).

How do i do this? There’ll be more checkboxes and radio buttons, i’ve used only 2 sets for this question.

<html> 
<head> 
<script type="text/javascript"> 
function DisplayFormValues() 
{ 
var str = ''; 
var elem = document.getElementById('frmMain').elements; 

for(var i = 0; i < elem.length; i++) 
{
str += elem[i].value+"<br>";
} 

document.getElementById('lblValues').innerHTML = str; 
} 

</script> 
</head> 
<body> 

<form id="frmMain" name="frmMain"> 
<INPUT TYPE="radio" NAME="r1" value="r1a">
<INPUT TYPE="radio" NAME="r1" value="r1b">
<INPUT TYPE="radio" NAME="r1" value="r1c">

<INPUT TYPE="checkbox" NAME="c1" value="c1a">
<INPUT TYPE="checkbox" NAME="c1" value="c1b">
<INPUT TYPE="checkbox" NAME="c1" value="c1c">

<input type="button" value="Test" onclick="DisplayFormValues();" /> 
</form> 
<hr /> 
<div id="lblValues"></div> 
</body> 
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:26:25+00:00Added an answer on May 17, 2026 at 9:26 pm

    Add the following test:

    if(elem[i].checked)
      str += elem[i].value+"<br>";
    

    Also, if you use jQuery, the whole script is even simpler:

    function DisplayFormValues(){
      $("input:checkbox:checked").add("input:radio:checked")
        .each(function(){
          $("div#lblValues").append(this.value + "<br>");
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the below script. two arrays with only three values.when i compare these two
I have a php script that uses curl to get the contents of a
I have a array which contains values like this See below for script sample
The aim is that I have a pair of radio buttons and each pair
I am using the script code below to get results from my database based
When I run the script below, I get $VAR1 = [ 'ok0.ok]][[file:ok1.ok', undef, undef,
I get the error shown below (73TypeError) on a small background animation script when
The script below works fine if 3 and 3.2 are not links but i
The script below should open all the files inside the folder 'pruebaba' recursively but
I have a function that makes an ajax call to get the initial data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.