C
Colin Steadman
I've create a simple survey using ASP. Its finished and
works, but one aspect of my coding is annoying me and I
cant figure out a better way of doing it.
Basically the questions are stored in an Access 2000 table
like this:
QUESTION_NUMBER QUESTION
1 Question 1 text....
2 Question 2 text....
3 Question 3 text....
4 Question 4 text....
5 Question 5 text....
My ASP page gets these questions and displays them in a
form dynamically. The user then answers the questions by
clicking radio buttons (Agree, Tend to agree, Not sure...
ect).
This works well and if I want to add a question I just
update the database table.
The problem is I've not been able to figure out how to
make the submit page dynamic. I'm having to manually add
code to my submit page to look after each question
individually rather than looping through the Form
collection.
For example when I build the SQL to update the database I
have to do it like this (note the last five lines look
after the responses to my five questions):
ReDim sqlValues(40)
sqlValues(0) = "values ("
sqlValues(1) = "'" & Session("emp_no") & "', "
sqlValues(2) = "'" & Session("Username") & "', "
sqlValues(3) = "'" & Session("sex") & "', "
sqlValues(4) = "'" & Session("phone") & "', "
sqlValues(5) = "'" & Session("job_title") & "', "
sqlValues(6) = "'" & Session("department") & "', "
sqlValues(7) = "'" & Session("age") & "', "
sqlValues(8) = "'" & Session("grade") & "', "
sqlValues(9) = "'" & Request.Form("1") & "', "
sqlValues(10) = "'" & Request.Form("2") & "', "
sqlValues(11) = "'" & Request.Form("3") & "', "
sqlValues(12) = "'" & Request.Form("4") & "', "
sqlValues(13) = "'" & Request.Form("5") & "', "
...
sql = Join(sqlValues)
Is there any possible way I can avoid having to hard code
the above and have the page work out what it needs to do
dynamically?
TIA,
Colin
works, but one aspect of my coding is annoying me and I
cant figure out a better way of doing it.
Basically the questions are stored in an Access 2000 table
like this:
QUESTION_NUMBER QUESTION
1 Question 1 text....
2 Question 2 text....
3 Question 3 text....
4 Question 4 text....
5 Question 5 text....
My ASP page gets these questions and displays them in a
form dynamically. The user then answers the questions by
clicking radio buttons (Agree, Tend to agree, Not sure...
ect).
This works well and if I want to add a question I just
update the database table.
The problem is I've not been able to figure out how to
make the submit page dynamic. I'm having to manually add
code to my submit page to look after each question
individually rather than looping through the Form
collection.
For example when I build the SQL to update the database I
have to do it like this (note the last five lines look
after the responses to my five questions):
ReDim sqlValues(40)
sqlValues(0) = "values ("
sqlValues(1) = "'" & Session("emp_no") & "', "
sqlValues(2) = "'" & Session("Username") & "', "
sqlValues(3) = "'" & Session("sex") & "', "
sqlValues(4) = "'" & Session("phone") & "', "
sqlValues(5) = "'" & Session("job_title") & "', "
sqlValues(6) = "'" & Session("department") & "', "
sqlValues(7) = "'" & Session("age") & "', "
sqlValues(8) = "'" & Session("grade") & "', "
sqlValues(9) = "'" & Request.Form("1") & "', "
sqlValues(10) = "'" & Request.Form("2") & "', "
sqlValues(11) = "'" & Request.Form("3") & "', "
sqlValues(12) = "'" & Request.Form("4") & "', "
sqlValues(13) = "'" & Request.Form("5") & "', "
...
sql = Join(sqlValues)
Is there any possible way I can avoid having to hard code
the above and have the page work out what it needs to do
dynamically?
TIA,
Colin