Solved

update using an option drop down list

Posted on 2002-07-22
5
132 Views
Last Modified: 2013-12-24
I have the following option selection drop down list:

<select name=keyword1 size=1>
<option name="keyword1" VALUE="#Trim(keyword1)#"></option>

<cfoutput query="keywords">
<option name="keyword1" value="#bookkeyword#" Selected>#bookkeyword#</option>
</cfoutput>

</select>

This allows me to select a keyword and add it to a database.  I now want to create an update or edit form that enables me to see what keyword was previously selected and change it if necessary.  I am having difficulty finding the proper code to set the keyword in the current option list so I can see what it was previously and then allow me to change it, subsequently passing it back to the database for updating.  I would appreciate help.

Can you also tell me how I can set this select list to initally show the first value in the list when a previous keyword has not been saved in the database table or when the keyword is being selected for the first time?

0
Comment
Question by:gcassel
  • 3
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
danrosenthal earned 100 total points
ID: 7170358
Sounds like what you are looking for is this....

<select name=keyword1 size=1>
<option VALUE="#Trim(keyword1)#"></option>

<cfoutput query="keywords">
<option value="#bookkeyword#" <CFIF bookkeyword eq keyword1>SELECTED</CFIF>>#bookkeyword#</option>
</cfoutput>

</select>
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 7170361
This will select the current value and if no value is set, then the default will be the first value.

You should take out the line "<option VALUE="#Trim(keyword1)#"></option>" it is not necessary.
0
 

Author Comment

by:gcassel
ID: 7170644
Thanks. I think this is what I want but I keep getting the error message:
"An error occurred while evaluating the expression:
 bookkeyword eq keyword1
Error near line 146, column 48.
Error resolving parameter KEYWORD1"
   My list of keywords comes from a cfquery called "keywords" but the actual data that I am trying to edit and update is stored in a table called "Books".  I have a cfquery therefore on this page called "Book" because it pertains to all of the information about one particular book in the Books Table (based on the BookID passed to this page by a previous page where the book that we want to edit was chosen from a list of all books). The "keyword1" here is therefore a keyword for the particular book chosen and on this page it is from the cfquery, "Book". "BookKeyword" on the other hand comes from the cfquery, "keywords".
  The use of the drop down option box all seems pretty basic and presenting a value for editing from an existing record also seems like it should not be too hard.  Unfortunately though the formatting of this output type is confusing to me.  I appreciate your patience and help.


0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 7170658
You seem to be very close.  The way you would call that variable is #book.keyword1#, without actual code to work with, all I can offer is the following:

<CFQUERY name="book" .....>
SELECT keyword1 .....
</CFQUERY>

<CFQUERY name="keywords" .....>
SELECT bookkeyword .....
</CFQUERY>

<cfoutput query="keywords">
<option value="#bookkeyword#" <CFIF bookkeyword eq book.keyword1>SELECTED</CFIF>>#bookkeyword#</option>
</cfoutput>
0
 

Author Comment

by:gcassel
ID: 7170808
Bingo!  Thanks.  I didn't realize you can call the query value without a cfoutput.
0

Featured Post

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Join & Write a Comment

Suggested Solutions

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now