[thelist] Javascript Help: Forms

Timothy Martens timfm at hawaii.rr.com
Wed Jul 3 18:53:01 CDT 2002

Hi -- another strange request. I have a form with four radio buttons.
The initial state of the radios is that NONE of them are "checked." I
want the function to make "checked = true" the first radio (r[0]) and
"return" when the user clicks anywhere in the document body and none are
checked. Subsequently (when a radio is checked) clicks will cycle
through the radio sequence -- this part works fine. It's just the
initial non-checked which is messing me    :\   mahalo!

  function N() {
  if (document.choice.r[i].checked = false)
{document.choice.r[0].checked = true; return;}
	//The rest works
    var rad = document.choice.r;
      for(var i=0; i < rad.length; i++) {
        if(rad[i].checked) {
          var nextRad = (i+1 >= rad.length) ? 0 : i+1;
          rad[nextRad].checked = true;
          checkedbutton = nextRad;
          //locked = 0;

document.onclick = N;

<form name="choice">
 <input type="radio" name="r" value="bg" />bg
 <input type="radio" name="r" value="txt" />txt
 <input type="radio" name="r" value="lnk" />lnk
 <input type="radio" name="r" value="blk" />blk


<!--timothy martens
timfm at hawaii.rr.com-->

More information about the thelist mailing list