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

Show previous entered data in form to update

Status
Not open for further replies.

trolldude

Technical User
Apr 29, 2004
14
GB
Hi

I am trying to create a questionniare and need the ability for the respondent to re-enter the questionnaire to edit previously entered data. I would like to be able to display this data so the respondent can check and update data if required. I have used the code below. PROBLEM If all the answers are changed then submitted it's ok. When 1 answer is changed and submitted I get an error.

Anybody any ideas as to why or an alternative method of doing this job.

Thanks trolldude

<code>
<td align="center" valign="middle"><cfif s1q1 IS 1><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#1#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 2><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#2#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 3><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#3#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 4><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#4#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 5><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#5#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 6><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#6#"></cfif></td>
</tr>
</code>
 
What error do you get? What does you're process code look like? Are you checking for any required fields? Is your only problem when the user makes one change and the update fails, yet when they make all changes the update is successful?

____________________________________
Just Imagine.
 
Hi
Thanks for your reply. Yes the error only appears when only 1 of the questions displyed is changed. I have included all the code for a question page and the processing code from the post page. Hope this is enough for you to quickly assess my problem. Maybe I'm going about this the wrong way? tearing my hair out over this one, any help would be very much appreciated.

Many thanks
Michael (Trolldude)

<code>
<!-- hide cfincude here <cfinclude template="header.cfm"> --->

<html>
<head>
<!-- change title -->
<title>Feedback Questionnaire - Section 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


<script type="text/javascript">

/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit This credit MUST stay intact for use
*/

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characters remaining on your input limit'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
}
}

</script>


</head>

<body>

<table width="720" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<!--DWLayoutTable-->
<tr>
<td width="29" height="32">&nbsp;</td>
<td width="669" align="left" valign="middle"><cfoutput><font size="3" face="Arial, Helvetica, sans-serif"><strong><font color="##0000CC" size="2">#session.UserFirstName# #session.UserLastName# </font></strong></font></cfoutput><font color="#000000" size="2"><strong><font face="Arial, Helvetica, sans-serif">giving
Feedback to</font></strong></font><font color="#0000CC" size="2"><strong><font face="Arial, Helvetica, sans-serif">
<cfoutput>#session.RecFirstName#</cfoutput></font></strong></font></td>
<td width="22">&nbsp;</td>
</tr>
<tr>
<td height="19">&nbsp;</td>
<td align="right" valign="top"><font color="#000099" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>See rating notes at bottom of page</strong></font></td>
<td>&nbsp;</td>
</tr>
</table>
<table width="710" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<!-- get answers data from database to update -->
<cfquery name="GetRecordtoUpdate" datasource="virtquest1">
SELECT * FROM example_data WHERE answerID
= #session.answerIDvalue#
</cfquery>
<cfoutput query="GetRecordtoUpdate">


<table width="720" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="##FFFFFF">
<!--DWLayoutTable-->
<!-- change form action -->
<form action="section5.cfm" method="Post">
<tr>
<td width="47" height="32" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td colspan="2" valign="middle"><strong><font color="##990000" size="3" face="Verdana, Arial, Helvetica, sans-serif">Section
1 - LEADERSHIP<br>
(1 of 12)
</font></strong></td>
<td width="28" rowspan="13" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td width="55" align="center" valign="middle"><div align="center"><strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Always</font></strong></div></td>
<td width="54" align="center" valign="middle"><p align="center"><strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Almost<br>
Always </font></strong></p></td>
<td width="49" align="center" valign="middle"><div align="center"><strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Some-<br>
times </font></strong></div></td>
<td width="54" align="center" valign="middle"><div align="center"><strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Almost<br>
Never </font></strong></div></td>
<td width="58" align="center" valign="middle"><div align="center"><strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Not<br>
Relevant</font></strong></div></td>
<td width="53" align="center" valign="middle"><div align="center"><strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Don't<br>
Know </font></strong></div></td>
</tr>
<tr>
<td height="58" align="center" valign="top"><font color="##990000" size="4" face="Arial, Helvetica, sans-serif"><strong>Q1</strong></font></td>
<td colspan="2" valign="top"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Purpose and Direction</strong><br>
Provides colleagues with a clear sense of purpose and direction</font></td>
<td align="center" valign="middle"><cfif s1q1 IS 1><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#1#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 2><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#2#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 3><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#3#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 4><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#4#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 5><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#5#"></cfif></td>
<td align="center" valign="middle"><cfif s1q1 IS 6><input type="radio" name="s1q1" value checked><cfelse><input type="radio" name="s1q1" value="#6#"></cfif></td>
</tr>
<tr>
<td height="78" align="center" valign="top"><font color="##990000" size="4" face="Arial, Helvetica, sans-serif"><strong>Q2</strong></font></td>
<td colspan="2" valign="top"><font color="##000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Delegating</strong><br>
Enlists the talents of others to help meet objectives by giving them activities and sufficient autonomy to exercise own judgment<br>
</font></td>
<td align="center" valign="middle"><cfif s1q2 IS 1><input type="radio" name="s1q2" value checked><cfelse><input type="radio" name="s1q2" value="#1#"></cfif></td>
<td align="center" valign="middle"><cfif s1q2 IS 2><input type="radio" name="s1q2" value checked><cfelse><input type="radio" name="s1q2" value="#2#"></cfif></td>
<td align="center" valign="middle"><cfif s1q2 IS 3><input type="radio" name="s1q2" value checked><cfelse><input type="radio" name="s1q2" value="#3#"></cfif></td>
<td align="center" valign="middle"><cfif s1q2 IS 4><input type="radio" name="s1q2" value checked><cfelse><input type="radio" name="s1q2" value="#4#"></cfif></td>
<td align="center" valign="middle"><cfif s1q2 IS 5><input type="radio" name="s1q2" value checked><cfelse><input type="radio" name="s1q2" value="#5#"></cfif></td>
<td align="center" valign="middle"><cfif s1q2 IS 6><input type="radio" name="s1q2" value checked><cfelse><input type="radio" name="s1q2" value="#6#"></cfif></td>
</tr>
<tr>
<td height="63" align="center" valign="top"><font color="##990000" size="4" face="Arial, Helvetica, sans-serif"><strong>Q3</strong></font></td>
<td colspan="2" valign="top"><font color="##000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Recognising others&rsquo; </strong><br>
Expresses positive expectation of others and recognises and respects their contribution</font></td>
<td align="center" valign="middle"><cfif s1q3 IS 1><input type="radio" name="s1q3" value checked><cfelse><input type="radio" name="s1q3" value="#1#"></cfif></td>
<td align="center" valign="middle"><cfif s1q3 IS 2><input type="radio" name="s1q3" value checked><cfelse><input type="radio" name="s1q3" value="#2#"></cfif></td>
<td align="center" valign="middle"><cfif s1q3 IS 3><input type="radio" name="s1q3" value checked><cfelse><input type="radio" name="s1q3" value="#3#"></cfif></td>
<td align="center" valign="middle"><cfif s1q3 IS 4><input type="radio" name="s1q3" value checked><cfelse><input type="radio" name="s1q3" value="#4#"></cfif></td>
<td align="center" valign="middle"><cfif s1q3 IS 5><input type="radio" name="s1q3" value checked><cfelse><input type="radio" name="s1q3" value="#5#"></cfif></td>
<td align="center" valign="middle"><cfif s1q3 IS 6><input type="radio" name="s1q3" value checked><cfelse><input type="radio" name="s1q3" value="#6#"></cfif></td>
</tr>

<tr>
<td height="19" colspan="10" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
<tr>
<td height="102" colspan="2" valign="top"><blockquote>
<p><font size="3" face="Arial, Helvetica, sans-serif"><strong>Comments<br>
</strong> <font size="2">(limited to 255 characters)</font> </font></p>
</blockquote></td>
<td colspan="10" valign="top"><font size="3" face="Arial, Helvetica, sans-serif">
<textarea name="s1comments" cols="50" rows="5" id="s1comments"></textarea>
<br>
<script>
displaylimit("","s1comments",255)
</script><br><br></font></td>
</tr>
<tr>
<td height="48" colspan="3" valign="top"><blockquote>
<p><font size="2" face="Arial, Helvetica, sans-serif"><strong>Click Submit button to save Section 1<br>
(Data displayed above will be saved)<br>
</strong></font>
<input type="submit" name="Submit" value="Submit">
</p>
</blockquote></td>
<td width="28" align="center" valign="middle"><strong><font size="3" face="Arial, Helvetica, sans-serif">OR</font></strong></td>
<td colspan="8" valign="top"><blockquote>
<!-- Hyperlink to next page -->
<p><font size="3" face="Arial, Helvetica, sans-serif"><strong><a href="section5.cfm">Click HERE to move to next section</a>
<font size="2">(NO data will be saved)</font></strong></font></p>
</blockquote></td>
</tr>
<tr>
<td height="2"></td>
<td width="125"></td>
<td width="197"></td>
<td></td>
<td width="55"></td>
</tr>
</form>
</table>
</cfoutput>

<cfinclude template="footer.cfm">

</body>
</html>

######## CODE FROM TOP OF NEXT POST PAGE ########


<cfquery name="UpdateRecord" datasource="virtquest1">
UPDATE example_data
SET s1q1 = #form.s1q1#,
s1q2 = #form.s1q2#,
s1q3 = #form.s1q3#,
s1comments = '#form.s1comments#'
WHERE answerID = #session.answerIDvalue#
</cfquery>

</code>
 
trolldude, I recreated your scenario on my end and noticed that you don't pass a value in your <cfif> statement only in your <cfelse> clause. See below:
Code:
<cfif s1q1 IS 1>
  <input type="radio" name="s1q1" [COLOR=red]value[/color] checked>
<cfelse>
  <input type="radio" name="s1q1" [COLOR=red]value="#1#"[/color]>
</cfif>

I rewrote all you're <input type="radio"> tags to be more sufficient, take a look:

Code:
          <td align="center" valign="middle"><input type="radio" name="s1q1" value="#1#" <cfif s1q1 IS 1>checked</cfif>></td>
          <td align="center" valign="middle"><input type="radio" name="s1q1" value="#2#" <cfif s1q1 IS 2>checked></cfif></td>
          <td align="center" valign="middle"><input type="radio" name="s1q1" value="#3#" <cfif s1q1 IS 3>checked></cfif></td>
          <td align="center" valign="middle"><input type="radio" name="s1q1" value="#4#" <cfif s1q1 IS 4>checked></cfif></td>
          <td align="center" valign="middle"><input type="radio" name="s1q1" value="#5#" <cfif s1q1 IS 5>checked></cfif></td>
          <td align="center" valign="middle"><input type="radio" name="s1q1" value="#6#" <cfif s1q1 IS 6>checked></cfif></td>

This works, tested it with success. Let me know if this solves your problem.

____________________________________
Just Imagine.
 
Thanks thats brilliant!works a treat.
Very grateful for the help I'll be off and do some donating to the cause for that. Hope this info will help other users of the forum.
Cheers
Michael
PS don't mean to be picky but you forgot to close the statements in all but the first line. You are more than forgiven though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top