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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping through controls... help please.

Status
Not open for further replies.

hopper

Programmer
Dec 5, 2000
27
0
0
US
I'm working on a online questionare. The site reads in the questions from a text file so the number of questions and radio button groups is unknown until the asp page runs. I need to validate that the user answered all the questions before the onclick event of the submit button. I am trying to use a javascript function to do this.

The problem I'm running into is how to append the for loop counter variable to the end of a control name.
ie. question1, question2, question3 ...

Here's my code (I know the array style syntax is incorrect, I just put it there to try to show what I was doing.)

function CheckAnswers(iCount)
{
for(int i=1, i<iCount, i++)
{
if (survey.question(i).value != 1)
{
//do something
}
}
}

Any help is greatly appreciated!!!

Thanks in advance,

Scott
 
Try (untested):
Code:
function CheckAnswers(iCount)
{
  var fld;
   for(int i=1, i<iCount, i++)
   { 
      fld = eval(&quot;document.forms[0].survey.question&quot; + i);
      if (fld.value != 1)
      {
         //do something        
      }
   }
}
 
That worked!!!

Thanks so much!!!

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top