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

Repopulation on error 2

Status
Not open for further replies.

Sherylj

Programmer
Jan 21, 2000
55
US
Here's the scenario. I have a form, it finds an error and sends them back to the original form with an error message that says fix the error. How do I repopulate a CFSELECT with the choice they made before the error?

I'm using session variables to repopulate input boxes, radio buttons, etc. but can't get the select drop down boxes to work. I don't want them to have to fill out the form again if they only have one little problem. Thanks.

Here's the code I have which is WRONG! Basically, if it's not defined query the database and give them the list, otherwise give it the value they had before the error.

<CFOUTPUT>
<CFIF IsDefined(&quot;session.AssignTo&quot;)>
<CFIF session.AssignTo IS NOT &quot;&quot;>
<cfselect name=&quot;AssignTo&quot;
size=&quot;1&quot;
message=&quot;Please select a name&quot;
query=&quot;gethelp&quot;
required=&quot;Yes&quot;
value=&quot;#session.AssignTo#&quot;>
</cfselect>
</CFIF>
<CFELSE>
<cfselect name=&quot;AssignTo&quot;
size=&quot;1&quot;
message=&quot;Please select a name&quot;
query=&quot;gethelp&quot;
required=&quot;Yes&quot;
value=&quot;StaffName&quot;>
</cfselect>
</CFIF>
</CFOUTPUT>

Sherylj :)
 
Hello SherylJ,

I've done that before like this:

Assuming you have the Select variable value in a Session variable.

Please Select a Name<Select name=&quot;Assignto&quot; size=1>
<cfoutput query=&quot;gethelp&quot;>
<option value=Assignto
<CFIF #Parameterexists(Session.Assignto)# is &quot;yes&quot; AND Session.Assignto = Assignto>Selected</CFIF> > #Assignto#
</cfoutput>


The Concept is simple. You are choosing whether or not to put the &quot;SELECTED&quot; into the <option... if the value of session.assignto is the same as the current row in the gethelp Query then you want that row selected. I've seen people use different methods but this always works for me.

Hope it helps.

HAVE FUN...

 
You are so right! I remember doing this now. I was trying to replace the value and not choose selected! Thanks!

Sheryl :)
 
This code is not working. Anybody else have any ideas?
I've tried several different methods and the select box doesn't know what to select.

<CFIF IsDefined(&quot;session.AssignTo&quot;)>
<CFIF session.AssignTo IS NOT &quot;&quot;>
<select name=&quot;AssignTo&quot; size=&quot;1&quot;>
<cfoutput query=&quot;getstaff&quot;>
<option value=&quot;#StaffName#&quot; selected>#StaffName#
</cfoutput>
</select>
</CFIF>
<CFELSE>
<select name=&quot;AssignTo&quot; size=&quot;1&quot;>
<cfoutput query=&quot;getstaff&quot;>
<option value=&quot;#StaffName#&quot;>#StaffName#
</cfoutput>
</select>
</CFIF>

And I've tried this

<CFIF IsDefined(&quot;session.AssignTo&quot;)>
<CFIF session.AssignTo IS NOT &quot;&quot;>
<select name=&quot;AssignTo&quot;
size=&quot;1&quot;
message=&quot;Please select a name&quot;
required=&quot;Yes&quot;>
<cfoutput query=&quot;getdata&quot;>
<CFIF #Parameterexists(Session.AssignTo)# is &quot;yes&quot;><option value=#session.Assignto# selected>
</CFIF>
</select>
</cfoutput>
</CFIF>
<CFELSE>
<cfselect name=&quot;AssignTo&quot;
size=&quot;1&quot;
message=&quot;Please select a name&quot;
query=&quot;gethelp&quot;
required=&quot;Yes&quot;
value=&quot;StaffName&quot;>
</cfselect>
</CFIF>

Ugghhhhhh!!! This is frustrating.
Thanks.
Sherylj ;)
 
And yes my session variable is getting set!
Sherylj :)
 
Hi again,

This right here is setting every option as &quot;Selected&quot;
Code:
<CFIF IsDefined(&quot;session.AssignTo&quot;)>
  <CFIF session.AssignTo IS NOT &quot;&quot;>
    <select name=&quot;AssignTo&quot; size=&quot;1&quot;>
      <cfoutput query=&quot;getstaff&quot;>
        <option value=&quot;#StaffName#&quot; selected>#StaffName#
     </cfoutput>
   </select>
  </CFIF>
[code]
You need to only set one as Selected.

I don't use <CFSELECT...  in these cases because it doesn't give you the same freedom.  Your second listing of code if it worked at all would give you your list of choices and then append one on the end that would be the same as the allready selected and it would actually be selected.  Try this:

[code]
<CFIF IsDefined(&quot;session.AssignTo&quot;)>
  <CFIF session.AssignTo IS NOT &quot;&quot;>
    <select name=&quot;AssignTo&quot; size=&quot;1&quot;>
    <cfoutput query=&quot;getstaff&quot;>
      <option value=&quot;#StaffName#&quot; <CFIF Session.AssignTo is &quot;#StaffName#&quot;>Selected<CFIF> >#StaffName#
    </cfoutput>
    </select>
  </CFIF>
<CFELSE> 
  <select name=&quot;AssignTo&quot; size=&quot;1&quot;>
  <cfoutput query=&quot;getstaff&quot;>
    <option value=&quot;#StaffName#&quot;>#StaffName#
  </cfoutput>
  </select>
</CFIF>
[code]

The Reason you have to put the <CFIF ... with the Selected inside the <CFOUTPUT ...   is because the <CFOUTPUT... makes a loop from the Query and does everything within the <CFOUTPUT></CFOUTPUT> once for each record in the Query.  With the above code then only the one record is Selected.  

IF you want to save space in your code you could even do this:

[code]
<select name=&quot;AssignTo&quot; size=&quot;1&quot;>
  <cfoutput query=&quot;getstaff&quot;>
    <option value=&quot;#StaffName#&quot; <CFIF IsDefined(&quot;session.AssignTo&quot;) AND session.Assignto IS &quot;#StaffName#&quot;>Selected</CFIF> >#StaffName#
  </cfoutput>
</select>
[code]

Then you only have to do it once.

Give it a try...
You know you love this job becase it's frustrating.
 
Here's the error with your first set of code. It doesn't like the cfif inside.


Error Occurred While Processing Request
Error Diagnostic Information
Context validation error in tag CFIF

The tag is not correctly positioned relative to other tags in the template: tag CFIF must have some content. This means that there must be at least one tag, some text, or even just whitespace characters between the <CFIF> and </CFIF> markers.

This problem may be due to a CFML comment that has no end comment mark.

The error occurred while processing an element with a general identifier of (CFIF), occupying document position (52:35) to (52:74).

The specific sequence of files included or processed is:
c:\inetpub\

Date/Time: 05/31/01 15:44:48
Browser: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Remote Address: 127.0.0.1



You're right I love a challenege and I love winning even more than that!! Can I please win now!!

Sherylj :)
 
I think I may have won! Second set of code seems to be working. Give me a minute, I'm sure I'll break it somehow!
Sherylj :)
 
Nope it's good to go! Thanks!!

Sherylj :)

p.s. I do love conquering this stuff! Even if it is with help.
 
SORRY...

I see my mistake

<CFIF IsDefined(&quot;session.AssignTo&quot;)>
<CFIF session.AssignTo IS NOT &quot;&quot;>
<select name=&quot;AssignTo&quot; size=&quot;1&quot;>
<cfoutput query=&quot;getstaff&quot;>
<option value=&quot;#StaffName#&quot; <CFIF Session.AssignTo is &quot;#StaffName#&quot;>Selected </CFIF> >#StaffName#
</cfoutput>
</select>
</CFIF>
<CFELSE>
<select name=&quot;AssignTo&quot; size=&quot;1&quot;>
<cfoutput query=&quot;getstaff&quot;>
<option value=&quot;#StaffName#&quot;>#StaffName#
</cfoutput>
</select>
</CFIF>



The Second code is better anyway unless there is more processing you need to do based on a re-populate.

HAVE FUN...
 
Typos! Gosh won't those make you crazy!
Thanks a million really. Big hurdle overcome.

Sheryl :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top