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 7028329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:22:22+00:00 2026-05-28T00:22:22+00:00

I wanna check radio buttons automatically: I tried this code but it does not

  • 0

I wanna check radio buttons automatically: I tried this code but it does not work:
Radio buttons have 3 different values, I wanna select the radio button with value ‘clean”.

How can I check automatically radio buttons on a webpage?
Thanks!

function getElements()
  {

  for (i=0; i<document.getElementsByTagName('input').length; i++) 
  {
    //if (document.getElementsByTagName('input')[i].type == 'radio')
    if(document.getElementsByTagName('input')[i].type=='radio')
    {
        //if (document.getElementsByTagName('input')[i].value=='clean')
        document.getElementsByTagName('input')[i].click();
    }
  }

I modified the code as following:

 for (i=0; i<document.getElementsByTagName('input').length; i++) 
  {

    if(document.getElementsByTagName('input')[i].type=='radio')
    {


        if(document.getElementsByTagName('input')[i].value == "clean")
        {
        document.getElementsByTagName('input')[i].checked =true;
        }

    }
  }

but it is not still working:(

the radio buttons are in a iframe, can it be the reason why the code is not working?

  • 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-28T00:22:23+00:00Added an answer on May 28, 2026 at 12:22 am

    Give your radio buttons “names” would make things a lot easier

    <input type="radio" name="myradios" value="clean"/>
    <input type="radio" name="myradios" value="somethingelse"/>
    
    var elements = document.getElementsByName('myradios');
    for (i=0;i<elements.length;i++) {
      if(elements[i].value == "clean") {
        elements[i].checked = true;
      }
    }
    

    Working example : http://jsfiddle.net/Dwzc9/

    Updated

    getElementsByName doesn’t seem to be supported in all IE versions … so you could use the following based on your original example :

    var allElems = document.getElementsByTagName('input');
    for (i = 0; i < allElems.length; i++) {
        if (allElems[i].type == 'radio' && allElems[i].value == 'clean') {
            allElems[i].checked = true;
        }
    }
    

    Working example : http://jsfiddle.net/Dwzc9/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query string called propID and I wanna check if the passed
i am looking for code to validate html color codes. wanna check if user
I have a string and it can contain values like this $string = '1,2,3,4,5';
I wanna do some local developer tests of IIS 7 but I don't have
I have got 8000 proxies. And I wanna check their types. For example: I
i wanna check out this thing called sproutcore , i need to install some
I have variable that get's value of checked radio button named: parentcheck I wanna
I wanna implement Facebook connect into my application on android. But i am not
Please check out my code here http://jsfiddle.net/bYDPr/20/ So I have some HTML textarea elements
I wanna check write script to check MI(Maintainability Index) value for COBOL code. 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.