[thelist] Stupid JS: Working with radio buttons

Ken Kogler ken.kogler at curf.edu
Tue Aug 20 13:31:01 CDT 2002

I've got some radio buttons:

  * 14 x 10 (<input type="radio" name="sSize" value="14x10">)
  * 7 x 10 (<input type="radio" name="sSize" value="7x10">)

And I'm trying to get the value of whichever one is checked. Here's what
worked for me:

function calc() {
  var limit = document.productForm.sSize.length;
  for (i=0;i<limit;i++) {
    if (document.productForm.sSize[i].checked == true) {
      var formSize = document.productForm.sSize[i].value;
  popupWin =

But if I've only got ONE radio button...

  * 10 x 12 (<input type="radio" name="sSize" value="10x12">)

...then the above code returns 'undefined' and my calc.asp script craps
out on me... I've been poking around some JS references, but they're not
very helpful, so it's time to ask the list.

All I want to do is have a function that looks through an unknown number
of radio buttons and finds the value of whichever one is checked. It
shouldn't be this hard... :)


More information about the thelist mailing list