Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forms - display responses NOT selected in previous form

Status
Not open for further replies.

ktpmm

Programmer
Jun 30, 2001
7
US
I have a form I am displaying to a user where they will check at least one (but maybe more) radio button(s). I want to see if the buttons are checked, and if they are NOT, read them into an array to be used on the next form (buttons that are checked are not displayed on the next form). Can anyone help me with this? This is what I have so far:

iCount = 0;
newarray = new Array();
for ( var i = 0; i < myForm.92.length; i++ )
{
if ( myForm.92.checked ) iCount++; { }
else {
// read into another array
newarray = myForm.92;
} // end else

} // end for

// now read them into new array
for (var k = 0; k< newarray.length; k++)
{
document.MainForm.99_.value = newarray;
}
 
You're asking for trouble by using element names that start with digits with the notation you're used to. You should use this format instead if you name elements that way:
Code:
myForm.elements['92'].length

Radio buttons with the same name are like an array, and only one can be selected in each array. If you want to allow multiple selec

Your logic is a bit off with building the new array, which will be the same size as the number of checkboxes, both checked and unchecked. Use something like this:

Code:
newarray = new Array(), ni=0;
 for ( var i = 0; i < myForm.elements['92'].length; i++ )
 {
   if ( myForm.elements['92'][i].checked ) iCount++; { }
  else  {
   // read into another array
   newarray[ni] = myForm.elements['92'][i].value;
   ni++;
   } // end else

 } // end for

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top