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

Select Box value question.

Guest
Oct 27, 2008 Oct 27, 2008
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
TOPICS
Database access
1.3K
Translate
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 ,
Oct 27, 2008 Oct 27, 2008
<option value="#vendor_ID#"#iif(vendor_ID EQ selected_vendor_id,DE('
selected="selected"'),DE(''))#>#vendor_name#</option>
Translate
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
Guest
Oct 27, 2008 Oct 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.?
Translate
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 ,
Oct 27, 2008 Oct 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.
Translate
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 ,
Oct 27, 2008 Oct 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.
Translate
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
New Here ,
Oct 08, 2009 Oct 08, 2009
LATEST

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!

Translate
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