Link to home
Start Free TrialLog in
Avatar of zebasdad
zebasdad

asked on

selectedindex in javascript for radio button

Why can't I access/set the SelectedIndex for a radio button in javascript?

var thisrb = document.getElementById("rbNewOrderType")
thisrb.SelectedIndex = 0;
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Radio buttons do not have a selectedIndex. What you need to do is:
var radioList = document.getElementsByTagName("rbNewOrderType");
for( var i=0; i < radioList.length; ++i)
{
   if( radioList[i].checked)
  {
       alert("Checked item: " + radioList[i].value)
  }
}

that will work if on your radio buttons you have name="rbNewOrderType"
Avatar of zebasdad
zebasdad

ASKER

I have seen this in other posts... but it does nothing at all... no error... just does nothing.

Because the radio button is in a dialog box... I also tried the source ID with ...  getElementById, but still no luck...  I can access my text boxes using the same source ID method.

var radioList = document.getElementById("DialogNewOrder_ctl00_rbNewOrderType");
for( var i=0; i < radioList.length; ++i)
{
   if( radioList[i].checked)
  {
       alert("Checked item: " + radioList[i].value)
  }
}
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your help!!...  I guess because it's inside a dialog box (Essential Objects)... I had to use the uniqueID (from the view source) in order to get your example working...  

var radioList = document.getElementsByName("DialogNewOrder$ctl00$rbNewOrderType");