> In your case, the cfselects is wonderful.
> Here's an example, where the current value is
> taken from the query "getuser": and the
> list of countries is taken from a query on
> a "countries" table called "getcountries":
> <cfselect name="country"
> label="What country are you from?"
> query="getcountries"
> display="countryname"
> value="countrycode"
> selected="#getuser.country#" />
> It automatically selects the option where the value
> matches the one in the
> "getcountries" query.
This is one of my favorite features of the onTap framework... Here's
the same select statement (including the same behavior) in one of my
forms:
<select name="country"
label="What country are you from?"
tap:query="getCountries"
tap:inputvalue="countrycode"
tap:inputlabel="countryname" />
:)
It works because the xhtml tag accepts a structure for the form's
current values (defaults to attributes scope) and I then simply append
the current set of properties from a DAO or other object/structure to
the attributes scope (so that if the form has been submitted, the form
values take precedence). If it's convenient, I can omit the inputvalue
and inputlabel attributes also if the inputvalue column has the same
name as the select element or is named "inputvalue" and the inputlabel
column is named "inputlabel". If the database contains a foreign key
constraint I can frequently omit the query all-together and allow the
form tools to produce the list of options automatically... So in a lot
of cases, it's even simpler:
<select name="country"
label="What country are you from?" />
So that produces all the options and pre-selects the appropriate
option.
God, do I love not typing. :)
Although I recommend always including an empty option at the top of
the element
<select name="country"><option /></select>
Unless you want to be inundated with people from Afghanistan. I
usually see that with US state selects and they get an unexplained
invasion of people from Alabama.
s. isaac dealey 434.293.6201
new epoch : isn't it time for a change?
add features without fixtures with
the onTap open source framework
http://www.fusiontap.com
http://coldfusion.sys-con.com/author/4806Dealey.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:235736
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54