Calling onclick on a radiobutton list using javascript

sajay picture sajay · Dec 12, 2008 · Viewed 381.9k times · Source

How do I call onclick on a radiobutton list using javascript?

Answer

Michael Haren picture Michael Haren · Dec 12, 2008

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