[thelist] Stupid JS: Working with radio buttons

Peter-Paul Koch gassinaumasis at hotmail.com
Tue Aug 20 14:56:00 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;
>   //alert(limit);
>   for (i=0;i<limit;i++) {
>     if (document.productForm.sSize[i].checked == true) {
>       var formSize = document.productForm.sSize[i].value;
>     }
>   }
>   popupWin =
>window.open('/products/calc.asp?sSize='+formSize,'Price_Calculator','wid
>th=400,height=300')
>}
>---------------------------------------------------------
>
>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'

Which browser? It might be that the array sSize isn't formed because there's
only one element of that name (didn't test this).

Maybe the simplest solution would be
   var limit = document.productForm.sSize.length;
   if (!limit) limit = 1;

ppk

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx




More information about the thelist mailing list