I have a script which stores values successfully to a database through textbox, drop-down and radio buttons. (going through "Update" and returning values in "View"
However, when I return to the "Edit" screen, from which I originally entered the values, only the text values are returned and the drop-down and radio values return as blank and have to be re-input as if new.
How do I have the selected values returned as showing when I go to "Edit"?
CASE EDIT
strSQL="SELECT tblQuestions.QuestionID, tblQuestions.Question, " & _
"tblQuestionData.QuestionDataID, tblQuestions.DataTypeID, " & _
"tblQuestionData.Value " & _
"FROM tblQuestions, tblQuestionData " & _
"WHERE tblQuestionData.QuestionID *= tblQuestions.QuestionID AND " & _
"tblQuestions.active = 1 " & _
"AND tblQuestionData.ReportDataID = " & ReportDataID
rst.Open strSQL, cxn
Response.Write "<form action='Reporting.asp?op=Update' method='post'>"
Response.Write "<input type='hidden' name='reportDataID' value='" & ReportDataID & "'>"
Response.Write "<table>"
do until rst.EOF
Response.Write "<tr>"
Response.Write "<th align='left'>" & rst("Question" & "</th>"
Response.Write "<td align='left'>"
QID=trim(rst("QuestionID")
Response.Write "<input type='hidden' name='QuestionDataID' value='" & rst("QuestionDataID" & "'>"
Response.Write "<input type='hidden' name='QuestionID' value='" & QID & "'>"
Value=FormatData(rst("Value",rst("DataTypeID") 'from formatfunctions.asp
'If data type is yes/no with radio buttons
If rst("DataTypeID" = 4 then
Response.Write "<INPUT type='radio' name='QuestionData" & QID & "' value='" & Value & "'>" & " Yes "
Response.Write "<INPUT type='radio' name='QuestionData" & QID & "' value='" & Value & "'>" & " No "
'If data type is drop-down w/several choices
Elseif rst("DataTypeID" = 5 then
Response.Write "<SELECT name='QuestionData" & QID & "' value='" & Value & "'>"
Response.Write "<OPTION VALUE=''>"
Response.Write "<OPTION value='Choice1'>CHOICE1"
Response.Write "<OPTION value='Choice2'>CHOICE2"
Response.Write "<OPTION value='Choice3'>CHOICE3"
Response.Write "</SELECT>"
If Data Type is text box
Else
Response.Write "<input type='text' name='QuestionData" & QID & "' value='" & Value & "'>"
End if
Response.Write "</td>"
Response.Write "</tr>"
rst.MoveNext
loop
Response.Write "<tr><td colspan='2' align='center'><input type='submit' name='sent' value='Update Report'></td></tr>"
Response.Write "</table>"
Response.Write "</form>"
rst.Close
Case "Update" '-----------------------------------------------UPDATE--------------------------------------------------------------------------------
ReportDataID=trim(Request.Form("ReportDataID")
if trim(Request.Form("sent")<>"" then
QuestionDataID=split(Request.Form("QuestionDataID",","
QuestionID=split(Request.Form("QuestionID",","
for i=lbound(QuestionID) to ubound(QuestionID)
if ubound(QuestionDataID)>=i then
QDID=trim(QuestionDataID(i))
end if
QID=trim(QuestionID(i))
Value=trim(Request.Form("QuestionData" & QID))
Value=replace(value,",",""
Value=replace(value,"$",""
if QDID<>"" then
strSQL="UPDATE tblQuestionData SET Value='" & Value & "' " & _
"WHERE QuestionDataID=" & QDID
else 'insert new record
strSQL="INSERT INTO tblQuestionData(QuestionID, ReportDataID, Value) " & _
"VALUES(" & trim(QuestionID(i)) & ", " & ReportDataID & ", '" & Value & "')"
end if
cxn.Execute strSQL
next
end if
Response.Redirect("Reporting.asp?op=View&ReportDataID=" & ReportDataID)
Case "View" '-----------------VIEW---------------------ReportDataID=trim(Request.QueryString("ReportDataID")
strSQL="SELECT tblReports.*, tblReportData.* " & _
"FROM tblReports, tblReportData " & _
"WHERE tblReports.ReportID=tblReportData.ReportID " & _
"AND tblReportData.ReportDataID=" & ReportDataID
rst.Open strSQL, cxn
Response.Write "<h2>" & Request.cookies("UserName" & " - " & rst("Title" & "</h2>"
Response.Write "<h3>Applicant: " & rst("Applicant" & "</h3>"
Response.Write "<table>"
rst.Close
strSQL="SELECT tblQuestions.QuestionID, tblQuestions.Question, " & _
"tblQuestionData.QuestionDataID, tblQuestions.DataTypeID, " & _
"tblQuestionData.Value " & _
"FROM tblQuestions, tblQuestionData " & _
"WHERE tblQuestionData.QuestionID *= tblQuestions.QuestionID AND " & _
"tblQuestions.active = 1 " & _
"AND tblQuestionData.ReportDataID = " & ReportDataID
rst.Open strSQL, cxn
do until rst.EOF
Response.Write "<tr>"
Response.Write "<th align='left'>" & rst("Question" & "</th>"
Value=FormatData(rst("Value",rst("DataTypeID") 'from formatfunctions.asp
Response.Write "<td>" & Value & "</td>"
Response.Write "</tr>"
rst.MoveNext
loop
Response.Write "</table>"
rst.Close
However, when I return to the "Edit" screen, from which I originally entered the values, only the text values are returned and the drop-down and radio values return as blank and have to be re-input as if new.
How do I have the selected values returned as showing when I go to "Edit"?
CASE EDIT
strSQL="SELECT tblQuestions.QuestionID, tblQuestions.Question, " & _
"tblQuestionData.QuestionDataID, tblQuestions.DataTypeID, " & _
"tblQuestionData.Value " & _
"FROM tblQuestions, tblQuestionData " & _
"WHERE tblQuestionData.QuestionID *= tblQuestions.QuestionID AND " & _
"tblQuestions.active = 1 " & _
"AND tblQuestionData.ReportDataID = " & ReportDataID
rst.Open strSQL, cxn
Response.Write "<form action='Reporting.asp?op=Update' method='post'>"
Response.Write "<input type='hidden' name='reportDataID' value='" & ReportDataID & "'>"
Response.Write "<table>"
do until rst.EOF
Response.Write "<tr>"
Response.Write "<th align='left'>" & rst("Question" & "</th>"
Response.Write "<td align='left'>"
QID=trim(rst("QuestionID")
Response.Write "<input type='hidden' name='QuestionDataID' value='" & rst("QuestionDataID" & "'>"
Response.Write "<input type='hidden' name='QuestionID' value='" & QID & "'>"
Value=FormatData(rst("Value",rst("DataTypeID") 'from formatfunctions.asp
'If data type is yes/no with radio buttons
If rst("DataTypeID" = 4 then
Response.Write "<INPUT type='radio' name='QuestionData" & QID & "' value='" & Value & "'>" & " Yes "
Response.Write "<INPUT type='radio' name='QuestionData" & QID & "' value='" & Value & "'>" & " No "
'If data type is drop-down w/several choices
Elseif rst("DataTypeID" = 5 then
Response.Write "<SELECT name='QuestionData" & QID & "' value='" & Value & "'>"
Response.Write "<OPTION VALUE=''>"
Response.Write "<OPTION value='Choice1'>CHOICE1"
Response.Write "<OPTION value='Choice2'>CHOICE2"
Response.Write "<OPTION value='Choice3'>CHOICE3"
Response.Write "</SELECT>"
If Data Type is text box
Else
Response.Write "<input type='text' name='QuestionData" & QID & "' value='" & Value & "'>"
End if
Response.Write "</td>"
Response.Write "</tr>"
rst.MoveNext
loop
Response.Write "<tr><td colspan='2' align='center'><input type='submit' name='sent' value='Update Report'></td></tr>"
Response.Write "</table>"
Response.Write "</form>"
rst.Close
Case "Update" '-----------------------------------------------UPDATE--------------------------------------------------------------------------------
ReportDataID=trim(Request.Form("ReportDataID")
if trim(Request.Form("sent")<>"" then
QuestionDataID=split(Request.Form("QuestionDataID",","
QuestionID=split(Request.Form("QuestionID",","
for i=lbound(QuestionID) to ubound(QuestionID)
if ubound(QuestionDataID)>=i then
QDID=trim(QuestionDataID(i))
end if
QID=trim(QuestionID(i))
Value=trim(Request.Form("QuestionData" & QID))
Value=replace(value,",",""
Value=replace(value,"$",""
if QDID<>"" then
strSQL="UPDATE tblQuestionData SET Value='" & Value & "' " & _
"WHERE QuestionDataID=" & QDID
else 'insert new record
strSQL="INSERT INTO tblQuestionData(QuestionID, ReportDataID, Value) " & _
"VALUES(" & trim(QuestionID(i)) & ", " & ReportDataID & ", '" & Value & "')"
end if
cxn.Execute strSQL
next
end if
Response.Redirect("Reporting.asp?op=View&ReportDataID=" & ReportDataID)
Case "View" '-----------------VIEW---------------------ReportDataID=trim(Request.QueryString("ReportDataID")
strSQL="SELECT tblReports.*, tblReportData.* " & _
"FROM tblReports, tblReportData " & _
"WHERE tblReports.ReportID=tblReportData.ReportID " & _
"AND tblReportData.ReportDataID=" & ReportDataID
rst.Open strSQL, cxn
Response.Write "<h2>" & Request.cookies("UserName" & " - " & rst("Title" & "</h2>"
Response.Write "<h3>Applicant: " & rst("Applicant" & "</h3>"
Response.Write "<table>"
rst.Close
strSQL="SELECT tblQuestions.QuestionID, tblQuestions.Question, " & _
"tblQuestionData.QuestionDataID, tblQuestions.DataTypeID, " & _
"tblQuestionData.Value " & _
"FROM tblQuestions, tblQuestionData " & _
"WHERE tblQuestionData.QuestionID *= tblQuestions.QuestionID AND " & _
"tblQuestions.active = 1 " & _
"AND tblQuestionData.ReportDataID = " & ReportDataID
rst.Open strSQL, cxn
do until rst.EOF
Response.Write "<tr>"
Response.Write "<th align='left'>" & rst("Question" & "</th>"
Value=FormatData(rst("Value",rst("DataTypeID") 'from formatfunctions.asp
Response.Write "<td>" & Value & "</td>"
Response.Write "</tr>"
rst.MoveNext
loop
Response.Write "</table>"
rst.Close