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

Keeping Values When Returning To Edit

Status
Not open for further replies.

GWPhoenix

IS-IT--Management
Jun 26, 2001
32
US
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 &quot;<form action='Reporting.asp?op=Update' method='post'>&quot;
Response.Write &quot;<input type='hidden' name='reportDataID' value='&quot; & ReportDataID & &quot;'>&quot;
Response.Write &quot;<table>&quot;
do until rst.EOF
Response.Write &quot;<tr>&quot;
Response.Write &quot;<th align='left'>&quot; & rst(&quot;Question&quot;) & &quot;</th>&quot;
Response.Write &quot;<td align='left'>&quot;
QID=trim(rst(&quot;QuestionID&quot;))
Response.Write &quot;<input type='hidden' name='QuestionDataID' value='&quot; & rst(&quot;QuestionDataID&quot;) & &quot;'>&quot;
Response.Write &quot;<input type='hidden' name='QuestionID' value='&quot; & QID & &quot;'>&quot;
Value=FormatData(rst(&quot;Value&quot;),rst(&quot;DataTypeID&quot;)) 'from formatfunctions.asp
'If data type is yes/no with radio buttons
If rst(&quot;DataTypeID&quot;) = 4 then
Response.Write &quot;<INPUT type='radio' name='QuestionData&quot; & QID & &quot;' value='&quot; & Value & &quot;'>&quot; & &quot; Yes  &quot;
Response.Write &quot;<INPUT type='radio' name='QuestionData&quot; & QID & &quot;' value='&quot; & Value & &quot;'>&quot; & &quot; No  &quot;
'If data type is drop-down w/several choices
Elseif rst(&quot;DataTypeID&quot;) = 5 then
Response.Write &quot;<SELECT name='QuestionData&quot; & QID & &quot;' value='&quot; & Value & &quot;'>&quot;
Response.Write &quot;<OPTION VALUE=''>&quot;
Response.Write &quot;<OPTION value='Choice1'>CHOICE1&quot;
Response.Write &quot;<OPTION value='Choice2'>CHOICE2&quot;
Response.Write &quot;<OPTION value='Choice3'>CHOICE3&quot;
Response.Write &quot;</SELECT>&quot;

If Data Type is text box
Else
Response.Write &quot;<input type='text' name='QuestionData&quot; & QID & &quot;' value='&quot; & Value & &quot;'>&quot;
End if
Response.Write &quot;</td>&quot;
Response.Write &quot;</tr>&quot;
rst.MoveNext
loop
Response.Write &quot;<tr><td colspan='2' align='center'><input type='submit' name='sent' value='Update Report'></td></tr>&quot;
Response.Write &quot;</table>&quot;
Response.Write &quot;</form>&quot;
rst.Close

Case &quot;Update&quot; '-----------------------------------------------UPDATE--------------------------------------------------------------------------------
ReportDataID=trim(Request.Form(&quot;ReportDataID&quot;))
if trim(Request.Form(&quot;sent&quot;))<>&quot;&quot; then
QuestionDataID=split(Request.Form(&quot;QuestionDataID&quot;),&quot;,&quot;)
QuestionID=split(Request.Form(&quot;QuestionID&quot;),&quot;,&quot;)

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(&quot;QuestionData&quot; & QID))
Value=replace(value,&quot;,&quot;,&quot;&quot;)
Value=replace(value,&quot;$&quot;,&quot;&quot;)

if QDID<>&quot;&quot; then
strSQL=&quot;UPDATE tblQuestionData SET Value='&quot; & Value & &quot;' &quot; & _
&quot;WHERE QuestionDataID=&quot; & QDID
else 'insert new record
strSQL=&quot;INSERT INTO tblQuestionData(QuestionID, ReportDataID, Value) &quot; & _
&quot;VALUES(&quot; & trim(QuestionID(i)) & &quot;, &quot; & ReportDataID & &quot;, '&quot; & Value & &quot;')&quot;

end if

cxn.Execute strSQL
next

end if
Response.Redirect(&quot;Reporting.asp?op=View&ReportDataID=&quot; & ReportDataID)

Case &quot;View&quot; '-----------------VIEW---------------------ReportDataID=trim(Request.QueryString(&quot;ReportDataID&quot;))

strSQL=&quot;SELECT tblReports.*, tblReportData.* &quot; & _
&quot;FROM tblReports, tblReportData &quot; & _
&quot;WHERE tblReports.ReportID=tblReportData.ReportID &quot; & _
&quot;AND tblReportData.ReportDataID=&quot; & ReportDataID

rst.Open strSQL, cxn
Response.Write &quot;<h2>&quot; & Request.cookies(&quot;UserName&quot;) & &quot; - &quot; & rst(&quot;Title&quot;) & &quot;</h2>&quot;
Response.Write &quot;<h3>Applicant: &quot; & rst(&quot;Applicant&quot;) & &quot;</h3>&quot;

Response.Write &quot;<table>&quot;

rst.Close

strSQL=&quot;SELECT tblQuestions.QuestionID, tblQuestions.Question, &quot; & _
&quot;tblQuestionData.QuestionDataID, tblQuestions.DataTypeID, &quot; & _
&quot;tblQuestionData.Value &quot; & _
&quot;FROM tblQuestions, tblQuestionData &quot; & _
&quot;WHERE tblQuestionData.QuestionID *= tblQuestions.QuestionID AND &quot; & _
&quot;tblQuestions.active = 1 &quot; & _
&quot;AND tblQuestionData.ReportDataID = &quot; & ReportDataID


rst.Open strSQL, cxn

do until rst.EOF
Response.Write &quot;<tr>&quot;
Response.Write &quot;<th align='left'>&quot; & rst(&quot;Question&quot;) & &quot;</th>&quot;

Value=FormatData(rst(&quot;Value&quot;),rst(&quot;DataTypeID&quot;)) 'from formatfunctions.asp
Response.Write &quot;<td>&quot; & Value & &quot;</td>&quot;
Response.Write &quot;</tr>&quot;
rst.MoveNext
loop
Response.Write &quot;</table>&quot;
rst.Close
 
Try using the SELECTED Keyword in the options:

Code:
<OPTION VALUE=''>&quot;
    <OPTION value='Choice1'>CHOICE1
    <OPTION value='Choice2' SELECTED>CHOICE2
    <OPTION value='Choice3'>CHOICE3
</SELECT>

and for a radio button use CHECKED:
Code:
<INPUT type='radio' name='QuestionData' value='No'>No
<INPUT type='radio' name='QuestionData' value='Yes' CHECKED>Yes
<INPUT type='radio' name='QuestionData' value='Maybe'>Maybe

Try using the radio button to see what happens with Request(&quot;QuestionData&quot;) to see different values when you select things...

Kevin

 
Thanks, but this does not work. When I return to edit, the values are still returned as blank (now defaulted where labeled &quot;Selected&quot; or &quot;Checked&quot;).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top