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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:59:03+00:00 2026-05-13T06:59:03+00:00

I am trying to implement a grid with radio button selector. When the radio

  • 0

I am trying to implement a grid with radio button selector. When the radio button is clicked, the row is set to a different color. Also, when a radio is selected in the grid, it needs to see if there was a previously selected radio button so that it could change the color set.

<script type="text/javascript">
var lastSelectedId = '';
function rowSelected(rdoButton) {

  if (rdoButton.id != lastSelectedId) {
    rdoButton.parentNode.parentNode.origClassName = 
      rdoButton.parentNode.parentNode.className;
    rdoButton.parentNode.parentNode.className = 'rowSelected';

    if (lastSelectedId != '') {
      var lastRadioButton = document.getElementById(lastSelectedId);
      lastRadioButton.parentNode.parentNode.className = 
        lastRadioButton.parentNode.parentNode.origClassName;
    }
  }
  lastSelectedId = rdoButton.id;
}
</script>

<table>
  <tr class="rowOdd">
    <td>
      <input type="radio" name="rdoGrpName" id="rdoId1" onclick="rowSelected(this);" />
    </td>
    <td>Blah</td>
  </tr>
  <tr class="rowEven">
    <td>
      <input type="radio" name="rdoGrpName" id="rdoId1" onclick="rowSelected(this);" />
    </td>
    <td>Blah</td>
  </tr>
</table>

I was wondering how I could remove the dependency on a global variable lastSelectedId to be able to track if there is a selected item? My initial idea is to save it to a dummy variable in the body object. like use this.

function rowSelected(rdoButton) {
  var mainBody = document.getElementByNames('body');
  if (rdoButton.id != mainBody[0].lastSelectedId) {
    // ....
  }
}

I was wondering if this is the right strategy for this. Also to make the code really unobstrusive, I need to add the event handler for the onload to initialize the global variable.

  • 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-13T06:59:04+00:00Added an answer on May 13, 2026 at 6:59 am

    Perfectly would it be, when you assigned event-handlers inside the script not by using onclick attributes. Then you could store everything in a separate scope.

    Now, you can also store the variable in a separete scope, but still the rowSelected/selectRow function has to stay in the global scope.

    BTW. instead of saving the ID you can store the reference to the node itself.

    var selectRow = (function(){
       var lastSelected, lastClass;
    
       return function(rdoButton){
          var p;
          if (rdoButton != lastSelected) {
             if (lastSelected) {
               p = lastSelected.parentNode.parentNode;
               p.className = lastClass;
             }
             p = rdoButton.parentNode.parentNode;
             lastClass = p.className;
             p.className = 'rowSelected';
          }
          lastSelected = rdoButton;
       }
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement pinch/stretch zooming on a ListBox: <ListBox Grid.Row=1 ManipulationCompleted=ListBox_ManipulationCompleted ItemsSource={Binding Paras}>
I am trying to implement Ext.ux.grid.filter.ListFilter using a data store (rather than a hardcoded
Details: I'm basically trying to implement the functionality of the example here ( http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editondblclick/defaultvb.aspx
I'm trying to implement datagridview's virtual mode but when i set RowCount to some
I am trying to implement struts2-jquery-grid. But I am stuck with the serialization issue.
I am trying to implement the following functionality: Flex data grid has 1 default
I've been trying to implement jQuery's grid function in my Asp.Net MVC app. I'm
I am trying to implement a snap grid using WPF and a canvas. I
I'm trying to implement a custom button on a jqGrid with hide and show
I did a custom button control in WPF and I am trying to implement

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.