Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to change SelectedIndex in RBL thru JavaScript? 1

Status
Not open for further replies.

EDB2

MIS
Sep 11, 2002
36
US
Is it possible to change the SelectedIndex of a RadioButtonList through JavaScript?

When a user uses the browser back button to return to the previous page, the page displays without reloading - so the previous selection is still selected. I would like to use the OnClientClick event to remove that selection and leave no element selected in the RadioButtonList when they click the button (forcing them to re-select an item).

I've seen several examples of how to tell which items in a RBL has been selected, but can't find anythign that would actually change the index of the selected item.
 
There is no such thing as a selectedIndex on a group of radio buttons (assuming you're talking about the same property seen on select lists)

What you'll have to do here to remove the selected item is to loop through each input element on the page, check it's .type property to see if it's a radio button, and if it is then set it .checked property to false.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
I have used code similer to this in the past"
Code:
function setAllRBLFalse() {
    
   for (counter = 0; counter < form1.YourRBLHere.length; counter++)
      {
        if (form1.YourRBLHere[counter].checked == true)
        {
             
            form1.YourRBLHere[counter].checked = false;                      
        }
            
      }
     
}
 
Benson, I think that's a better answer than the ones I gave on the other forum, and much simpler. I got thrown off by the fact that the radio button list exists in a table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top