Calling onclick on a radiobutton list using javascript

How are you generating the radio button list? If you’re just using HTML:

<input type="radio" onclick="alert('hello');"/>

If you’re generating these via something like ASP.NET, you can add that as an attribute to each element in the list. You can run this after you populate your list, or inline it if you build up your list one by one:

foreach(ListItem RadioButton in RadioButtons){
    RadioButton.Attributes.Add("onclick", "alert('hello');");
}

More info: http://www.w3schools.com/jsref/event_onclick.asp

Leave a Comment