Skip to main content
October 27, 2008
Question

Select Box value question.

  • October 27, 2008
  • 4 replies
  • 1323 views
Greetings:

I have a form page that displays information to be edited with several DD select boxes. All have numerical values (CF_SQL_INTEGER).

I don't want to display the first option from the results query in a box, because if the user makes no changes to that field, the value of that choice will replace the real value, e.g. if State field shows Texas, and the address was not changed, the value sent to the State field would be Alabama.

I don't want to give it a value of "0" , and giving it no value sends the text string "select" :

<cfselect name="location_vendor_ID" class="inputtext">
<option>--- Select ---</option>

<cfloop query="get_vendor"><option value="#vendor_ID#">#vendor_name#</option></cfloop>

</cfselect>

Any help appreciated...

rinorman
This topic has been closed for replies.

4 replies

Participant
October 8, 2009

I know it has been a year on this, but this:

<option value="#vendor_ID#"#iif(vendor_ID EQ selected_vendor_id,DE('
selected="selected"'),DE(''))#>#vendor_name#</option>

was a fantastic piece of code! Thank you so much!

Inspiring
October 27, 2008
First, using cfquery instead of cfupdate gives you more flexibility.

Second, I had a situation similar to yours once and cheated on the data. I added dummy records to the db tables to account for the extra options in the dropdown lists.
Inspiring
October 27, 2008
Why don't you want to give it a value of 0? It's pretty easy to work with both on making it mandatory to select something else on the form page, and checking to see what was selected on the action page.
Inspiring
October 27, 2008
<option value="#vendor_ID#"#iif(vendor_ID EQ selected_vendor_id,DE('
selected="selected"'),DE(''))#>#vendor_name#</option>
October 27, 2008
Ian:

Thanks for your quick response.

To clarify, I first show the current Vendor:

<cfquery name="get_current_vendor" datasource="#Request.BaseDSN#">
SELECT *
FROM lookup_vendor
WHERE vendor_ID = #location_vendor_ID#</cfquery>

<tr>
<td>Current Vendor:</td>
<td><cfloop query="get_current_vendor">#vendor_name#</cfloop>
</td></tr>

Then the opportunity to change it:

<cfquery name="get_vendor" datasource="#Request.BaseDSN#">
SELECT *
FROM lookup_vendor
ORDER BY vendor_name</cfquery>
<tr>
<td>New Vendor:</td>
<td>
<cfselect name="location_vendor_ID">
<cfloop query="get_vendor">
<option value="">--- Select ---</option>
<option value="#vendor_ID#">#vendor_name#</option></cfloop>
</cfselect>

I also tried something like:

<cfif #location_vendor_ID# EQ #get_current_vendor.location_occupancy_ID#> (query of the query)

<option value>#Make this the selected option#</option>

Dan: If I assign "0" as the value, it will replace the current vendor ID with "0".

I'm using cfupdate - should I be using <cfquery>update etc.?