faqts : Computers : Programming : Languages : JavaScript : Forms : Radio buttons

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

21 of 31 people (68%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How do I associate an event handler with a radio button (or even group)?

Aug 23rd, 2000 10:16
Martin Honnen, Kishore Kothapalli,


An event handler is always for a single input element not a group so 
you can do
  function clickHandler (evt) {
    alert(this.name + ': ' + this.value + ' clicked.');
  }
  document.formName.radioButtonName[index].onclick = clickHandler;
or in a loop for every radio button
  var rbg = document.formName.radioName;
  for (var i = 0; i < rbg.length; i++)
    rbg[i].onclick = clickHandler;