Hi all,
I've got a spot of bother with my radiobuttonlist. It has 3 items in it and I want them to control the visibility of certain divs/tables.

But even simple text changes are becoming a headache and the postback is not firing the event I clicked on but the PREVIOUS event (ie, I click on value 1 and text shows nothing, I click on value 2 and text shows value 1, I click on value 3 and text shows value 2)...always 1 step behind.

Here's my code:

function SetMessageInTextbox() {
var rdolist_0 = document.getElementById("rdolist_0");
var rdolist_1 = document.getElementById("rdolist_1");
var rdolist_2 = document.getElementById("rdolist_2");
if (rdolist_0.checked)
if (rdolist_1.checked)
if (rdolist_2.checked)	

I've tried combinations of adding attributes in the vb.net pageload function, the vb.net code behind rdoList.selectindexchange using
rdolist.Attributes.Add("onload", "javascript:SetMessageInTextbox()")
and also the onClick event of the HTML page.

If you can assist, please do.

8 Years
Discussion Span
Last Post by phantom1000000

You can use the below javascript method to read asp radio button list selectindex, selected value.

<script type="text/javascript">

function GetRadioButtonSelectedValue()
var AspRadio = document.getElementsByName('Aspradiobuttonlist');

for (var i = 0; i < AspRadio.length; i++)

if (AspRadio[i].checked)
var lblAspradiobuttonValue = document.getElementById('<%= lblAspradiobuttonValue.ClientID %>');

lblAspradiobuttonValue.innerHTML='<b>Selected Value:</b> '+AspRadio[i].value+'<br/>';
lblAspradiobuttonValue.innerHTML+='<b>Selected Text:</b> '+AspRadio[i].parentNode.getElementsByTagName('label')[0].innerHTML;
}//end if

}// end for

}//end function

WHERE Aspradiobuttonlist is the id of radiobuttonlist server control.

Hope it will help you.

Edited by mail2saion: n/a



Thanks for the reply. Unfortunately, you're code doesn't have the desired result. What does seem to happen is that if I make a selection, no answer will appear, but if I next press the area around a radiobutton, but still on the radiobuttonlist control, it will respond with the correct response.

So in other words, the change of index doesn't fire the function, but clicking the list (not a direct radiobutton) does.

This is counter-intuitive if you ask me and I can't expect the users of the page to do this.

Any clues?

Thanks again.


Okay, just figured it out. Now I think about it, it makes a bit of sense. I forgot javascript gets loaded with the page and therefore it does not need to post back to the server. I had autopostback set to true and by setting this to false, the desired effect came into play.

Thank you for your help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.