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

In the below code how to get the checkboxes that are selected only and
consider the below script. two arrays with only three values.when i compare these two
I've created buttons that have been edited with css to look like hyperlinks so
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
I have the following script. It replaces all instances of @lookFor with @replaceWith in
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I have a script that retrieves objects from a remote server through an Ajax
I have a Perl script that I'm attempting to set up using Perl Threads
I have an Ant script that performs a copy operation using the 'copy' task
My understanding: in Javascript objects and arrays get passed as references not values for

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.