p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: looping through dynamically created form fields


Message #1 by "Daniel O'Dorisio" <daniel@2...> on Fri, 23 Feb 2001 02:20:31
Yes, they are only one answer, per question. The reason I was thinking about
looping though the choices/answers table is because I cant remember, I think
it was because I have all my choices in a table. I am just confusing my
self. Im going to try what you are saying, and see if I can go from there.

Once again thanks a million!!

Daniel

Daniel O'Dorisio
Daniel@2...

-----Original Message-----
From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...]
Sent: Friday, February 23, 2001 9:03 AM
To: Code Clinic
Subject: RE: looping through dynamically created form fields

I was thinking along the lines of

if oRS is a recordset that contains a list of all the QIDs of the questions
used in this quiz

do until oRS.eof

sAnswer = request.form("f" & oRS(0))

'now insert answer into database

oRS.moveNext

Loop

e.g. no need to loop through the answers

are all your multiple choice questions one answer only? It might get a bit
messy if theres a question which allows multiple answers

-----Original Message-----
From: Daniel O'Dorisio [mailto:daniel@2...]
Sent: Friday, February 23, 2001 12:32 PM
To: Code Clinic
Subject: RE: looping through dynamically created form fields


So you are saying to loop through the answer fields for the appropriate
question? And then use request("f" & rst("field") &")  to get the proper
form input field? Or in other words, I would use a DO...Loop to loop through
the list of answers for the given question and then evaluate each question.
Hey, sounds good to me, I knew it would be simple.

THANKS!!!!

Daniel O'Dorisio
Daniel@2...
#3

Daniel O'Dorisio
Daniel@2...

-----Original Message-----
From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...]
Sent: Friday, February 23, 2001 5:29 AM
To: Code Clinic
Subject: RE: looping through dynamically created form fields

Each question should have some kind of unique identifier, then you would
have a table which stores the question ids that make up the quiz.  Each
input should have a name that is derived from question identifier (eg if Qid
= 234, field name='F234').  Then when you come to saving the answers, you
can read the table of which questions are in the quiz, and then you can
determine the field names to request.

-----Original Message-----
From: Daniel O'Dorisio [mailto:daniel@2...]
Sent: Friday, February 23, 2001 2:21 AM
To: Code Clinic
Subject: looping through dynamically created form fields


Hello, i have a question about the possibility of looping through several
dynamically created form elements (text and radio buttons). for example, i
am developing a online quiz that draws all the information out of a
database, this way the owner of the site can edit the data in the quiz
without knowing any javascript or html. so anyway.

the situation is, a page (ASP) pulls out the data and writes it in the
following format:

Question: {text of question}
then if it is a multiple choice the page writes a group of option buttons
with the value of the option button as the value of the choice. if it is a
fill in the blank it writes a empty text box, if it is a t/f it writes 2
radio buttons with the values of true and false (these values are pulled
out of the database also)

With me?

i can draw the data out fine, no problem. but my problem comes at the
point when i need to put the answers that the user selected back in the
database, how can i loop through all the fields, and post the values in a
database table?? it would be easy if they all had static names, then i
could treat each one accordingly. but this whole thing has to be dynamic.
i saw one way of doing it with a for next loop kinda like:

For n = 1 to Request("fieldnames").count  'fieldnames is the name for all
of the fields.

   'do the update or insertion here

Next

but i never got this to work, when i requested the formvalues i got the
list of all the values, (1, 2, 3 instead of 1 then on the next time 2 then
on the next time 3)

if any of yall have some ideas on how i can accomplish this i will really
appreciate it, even if it is a totally different architecture. basically
all i am trying to do is create a quiz of 15 questions(5 per page) that is
composed of multiple choice true/false, and fill in the blank.  also on
the 4th page of the quiz(an answer page, yes i know 15 divided by 5 is 3:)
i, or actually the person i am developing it for wants to display the ones
that they got wrong, but not the actual answer.

i have a "beta" design worked out, and am getting ready to write the code,
but i got stumped on how i will process the answers.


i hope this makes since, and i really appreciate anyone that has some help
for me. i am not a very expierenced developer, i am only 15 and have just
been working with asp for amybe a year. but i am willing to read, so if
you have any pointers on where to get information that will be appreciated
as well.

Thanks ALOT!!

Daniel O'Dorisio
#3

  Return to Index