• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFLOOP and OPTION selected

Guest
May 01, 2006 May 01, 2006

Copy link to clipboard

Copied

Hi, can anyone help.

Here is the basic idea, working on a shop which displays 9 tshirts, 3x3. Want the admin of the shop to be able to select which 9 shirts will be shown to the user.

I have a loop which puts all the items in order, and i know I could use individual cfqueries for every cell in the table, but thought Id try something better.

It seems to put 'selected' at most of the options in each drop down menu! not just the one currently chosen by the shop person the last time!

I want the loop to populate the drop down menus, and if the item is the current selection, then it is selected. not the others.

Can someone help.

This is the admin, very basic! The site

Many Thanks

code:

<cfif IsDefined("form.submit")>
<cfset loop = 1>
<cfloop index="i" from="1" to="9">
<cfset images = 'form.image' & #loop#>

<cfquery name="idshirt" ...
SELECT ShirtID, title, image
FROM proart
WHERE image = "#Evaluate("form.image" & loop)#"
</cfquery>

<cfquery name="update" ...
UPDATE proartmenu
SET image = "#idshirt.image#", ShirtID = "#idshirt.ShirtID#", title = "#idshirt.title#"
WHERE PicID = #loop#;
</cfquery>
<cfset loop = loop + 1>
</cfloop>
</cfif>


<cfquery name="shirts" ...
select * from proart;
</CFQUERY>



<CFSET max_seq = #shirts.recordcount#>
<CFSET max_rows = INT((#max_seq# +2)/3)>
<CFSET x = 0>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
.selected { background-color:#CCCCCC;}
</style>
</head>

<body><form id="form" name="form" method="post" action="pop.cfm">

<table width="90%" height="90" border="1" align="center">
<CFLOOP INDEX="seq_no" FROM="1" TO="#max_rows#">
<TR>
<CFLOOP INDEX="sequence" FROM="1" TO="3">
<CFSET x = x + 1>

<TD>
<select name="image<cfoutput>#x#</cfoutput>">
<cfoutput query="shirts">
<CFQUERY NAME="themenu" ...
SELECT * FROM proartmenu
WHERE PicID = #x#;
</CFQUERY>

<CFQUERY NAME="theshirts" ...">
SELECT * FROM proart;
</CFQUERY>

<cfif themenu.image IS NOT theshirts.image>
<option value="#Image#">#Title#</option>
<cfelse>
<option value="#Image#" selected="selected" class="selected">#Title#</option>
</cfif>

</cfoutput>
</select>

</TD>
</CFLOOP>
</TR>
</CFLOOP>




</table>
<input name="submit" type="submit" />
</form>

</body>
</html>

TOPICS
Advanced techniques

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 02, 2006 May 02, 2006

Copy link to clipboard

Copied

LATEST
So your goal is to pre-select options in a multi-select? Here is the general idea.

Run two cfqueries, q1 and q2. q1 selects all available items and q2 selects the ones you want to preselect. Let's call the fields id and name.

<select multiple etc>
<cfoutput query = "q1">
<option name = "id" value = "#id#"
<cfif ListFind(ValueList(q2.id), id)>"selected"</cfif>
>
</cfoutput>
</select>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation