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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:26:40+00:00 2026-05-27T04:26:40+00:00

What I need to do is check to see if the checkbox is checked,

  • 0

What I need to do is check to see if the checkbox is checked, and if so, select all the radio buttons located within the same element?

I’ve set up the elements with id’s, b/c that is the “physical” grouping of the elements that will be affecting each other.

I’m trying to do something like this onchange(‘some_row_id’):

function select_row(row_id) {
  // Get 1st td element (where checkbox is located) and assign its
  // checked value to variable "checked"
  var checked = document.getElementById(row_id).td[0].input.checked;

  if(checked) {
    var children = document.getElementById(row_id).childNodes;
    for(var i = 0; i< children.length; i++) {
      if(children.td.type == radio) {
        children.td.radio = checked;
      }
    }
  }
}

I know that javascript is almost 200% wrong, but I can’t figure out how to properly select only td children (or prefereably, only input grandchildren) of a tr element and check them.

Here’s the basic form structure in actual working html:

<form name="form2" action="testfile4.php" method="get">
<table border="1"><thead>
    <tr><th>Select entire row</th><th>item_code</th><th>description</th><th>page</th>
      </tr>
</thead>
<tbody>
    <tr id="534">
        <td ><input type="checkbox" onchange="select_row(534);"></td>       <td>15038         <input type="radio" name="15819-038|item_code" value="534" /></td>
        <td>For 1st item,  alternate 1
        <input type="radio" name="15819-038|description" value="534" /></td>
        <td>5
          <input type="radio" name="15819-038|page" value="534" /></td>
      </tr>
    <tr id="535">
        <td ><input type="checkbox" onchange="select_row(535);"></td>       <td>15038         <input type="radio" name="15819-038|item_code" value="535" /></td>
        <td>For 1st item, alternate 2         <input type="radio" name="15819-038|description" value="535" /></td>
        <td>5
          <input type="radio" name="15819-038|page" value="535" /></td>
      </tr>
    </tbody>
    </table>
    </form>

EDIT:
I’m willing to accept jquery solutions. Thank you.

EDIT 2:
Thanks to nnnnnn. I used your JS and added this to have the uncheck behavior I wanted. If you want you can update your answer with it and I’ll remove it from here:

 else if (!row.cells[0].childNodes[0].checked) {
        inputs = row.getElementsByTagName("input");
        for(var i=0; i<inputs.length; i++) {
            if(inputs[i].type === "radio") {
                inputs[i].checked = false;
            }
        }
    }
  • 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-27T04:26:41+00:00Added an answer on May 27, 2026 at 4:26 am

    Well here’s one way to do it:

    function select_row(row_id) {
       // get a reference to the row based on the id passed in
       var row = document.getElementById(row_id),
           inputs;
    
       // .cells[0] gives the row's first td element,
       // then .childNodes[0] gives that td's first child element which
       // will be the checkbox
       if (row.cells[0].childNodes[0].checked) {
          // getElementsByTagName gives all descendent elements with the matching
          // tag, not just direct children, so get all the inputs for the current
          // row and loop through them looking for the radios
          inputs = row.getElementsByTagName("input");
          for (var i=0; i<inputs.length; i++) {
             if (inputs[i].type==="radio")
                 inputs[i].checked = true;
          }
       }
    }
    

    And change your checkbox to use onclick=... instead of onchange=....

    Note that using checkboxes to select a row doesn’t really make sense because after selecting one, if you click another row’s checkbox the first row’s checkbox is still checked. You might be better off with a button or <a> element for this purpose.

    Note also that instead of passing the row ID to the function and then getting a reference to that row using the ID, like this:

    <input type="checkbox" onclick="select_row(534)">
    
    function select_row(row_id) {
       var row = document.getElementById(row_id);
       // etc
    

    You can directly pass a reference to the checkbox that was clicked and use that instead:

    <input type="checkbox" onclick="select_row(this);">
    
    function select_row(cb) {
       var row = cb.parentNode.parentNode;
       if (cb.checked) {
          // etc
    

    However in my full solution above I stuck with passing the ID like you did in case you are calling the function from somewhere other than just the click event.

    There were several things wrong with your code as posted:

    • You can’t get children of a particular element just by refering to their type, e.g., getElementById(row_id).td[0].input doesn’t work. To get the first td you can use a row’s cells collection and say .cells[0] (like in my code).

    • Your for loop doesn’t use the i variable within the loop to select the individual items. You should’ve said children[i] within the loop.

    • Your if statement: if(children.td.type = radio) { is doing an assignment (single = sign) instead of a comparison (double == or triple === equals sign), and should be comparing to the string "radio" (with quotes).

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

Sidebar

Related Questions

I need to check to see if a variable is null or has all
I need to check to see if a directory is empty. The problem is,
I need to check a directory to see if there are any files whose
I need to check specific positions in an NSArray to see if they have
When our server comes up we need to check a file to see how
I need to check some settings for all users on Windows clients in the
Possible Duplicate: Checkbox Stays Checked on Page Refresh Please see the image carefully. This
I need to check and see if the Server service is running. Easy enough,
I'm creating and editing groups. I need to check to see if a group
I need to check to see if a variable contains anything OTHER than a-z

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.