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

Defaulting fields in an array to blank

Status
Not open for further replies.

programmher

Programmer
May 25, 2000
235
0
0
US
I have a form that could have up to 100 columns (based on what the user selects). I want all but the first 3 columns to default to the word BLANK. My below code is not working for all the fields - only for six fields throughout my entire form. Can anyone tell me why?

<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;100&quot; step=&quot;1&quot;>
<cfset cname='column' & #i#>
<cfif #i# le listlen(attributes.selectedcols)>
<cfset selcount=i>
</cfif>

<td><cfselect name=#cname# size=&quot;1&quot; required=&quot;Yes&quot;>
<cfif i GT 1 >
<option value=&quot;empty&quot;>Blank
</cfif>
<cfloop index=&quot;count&quot; from=&quot;1&quot; to=&quot;#listlen(allfields)#&quot; step=&quot;1&quot;>
<cfif columnsort is 1>
<cfoutput>
<option value=#sfieldarray[count][1]#
<cfif #listgetat(attributes.selectedcols,selcount)# is #sfieldarray[count][1]#>SELECTED</cfif>
>#sfieldarray[count][2]#</cfoutput>
<cfelse>
<cfoutput><option value=#fieldarray[count][1]# <cfif #listcontainsnocase(listgetat(attributes.selectedcols,selcount),fieldarray[count][1])#>SELECTED</cfif>>#fieldarray[count][2]#</cfoutput>
</cfif>
</cfloop>
</cfselect></td>
<cfif #i# mod 10 eq 0></tr></cfif>
</cfloop>
 
The first problem is that your &quot;BLANK&quot; <option> in each <select> isn't closed. The browser should be able to figure out what you mean because <option> tags can't be nested, but fixing that would be a good start.

Beyond that, it's hard for me to get a handle on your data flow because it seems very complex. But it looks to me like in the part where you loop over the allfields list to write the other <option> tags, every tag will have the SELECTED attribute. This is invalid and will certainly not give you the results you want. Only one <option> in each <select> should have the SELECTED attribute, and if you want the <select> boxes to default to &quot;BLANK&quot;, that is the <option> that should have the SELECTED attribute.

Do a &quot;View Source&quot; on the resulting HTML page to see if my impression is correct that every <option> tag has the SELECTED attribute. If so, there's your culprit.

-pcorreia
Did I help? Vote!
 
Pcorreia,

Thanks a million! I guess I just needed a pair of fresh eyes to see the obvious!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top