How do I make the first entry in a CFSELECT blank/empty?

I am using the CFSELECT statement below to populate a drop-down box. I need the first choice to be left blank. Other than creating a blank or NULL option in the database, it is possible? I need to make the first option blank and the drop-down required. Below is what I am using - thank you.

 <cfselect name="TypeOfWidget"
             query="TypeOfWidget"
             value="TypeOfWidget"
             display="TypeOfWidget"
             selected="#VARIABLES.TypeOfWidget#">
   </cfselect>
earwig75Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gdemariaCommented:
Just do it manually instead..

<select name="typeofwidget"....>
    <option value="">Select One</option>
    <cfquery name="xxx">
        <option value="getQuery.value"> #getQuery.label#</option>
     </cfquery>
</select>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
earwig75Author Commented:
What would I use for getQuery.value and getQuery.label in your example? I'm sorry I am a bit confused and should mention I am a beginner.
0
gdemariaCommented:
All of the values you've shown are "typeOfWidget" .. basically the real values you would put into that CFSELET statement would go into these places.

<select name="typeofwidget"....>
    <option value="">Select One</option>
    <cfquery name="getData"
        <option value="#getData.widgetID#"> #getData.widgetName#</option>
     </cfquery>
</select>


Assuming your query is called getData and it fetches from widgets table which has a widgetID and a widgetName, you would do the above.

basically the VALUE has the value you want to pass in the form field when submitted and the LABEL (or widgetName in my example) is what you would show to the user..

If you had used real values in your statement, I could have shown you real values here..
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

_agx_Commented:
basically the VALUE has the value you want to pass in the form field when submitted and the LABEL (or widgetName in my example) is what you would show to the user..

To elaborate, we assume most db tables have a unique numeric ID to go along with the user-friendly title (ie TypeOfWidget column)

WidgetID, TypeOfWidget
1, Widget A       <=== user friendly title
2, Widget B
3, Widget C
...

<cfselect
                       value="TypeOfWidget"
                       display="TypeOfWidget" ...

Right now you're using the title for both the "display" and "value".
         ie  Result is <option value="Widget A">Widget A</option>

But typically you should use the numeric id for the value instead
        ie <option value="1">Widget A</option>
0
earwig75Author Commented:
Thank you. So the value us what would get written to my master table? Would I then need to have additional code when viewing the record to say value 1 is widget A?
0
_agx_Commented:
So the value us what would get written to my master table?

Yes.
       
Would I then need to have additional code when viewing the record to say value 1 is widget A?

We'd have to see the query, but most likely yes. This is a silly example, but say you insert the #form.TypeOfWidget# value into another table called "Orders".

      OrderID | OrderDate | Quantity | WidgetID
      1 | 3/15/2012 | 3 | 1       <=== 1 is Widget A

Then want to list the orders and names of the widgets. Yes, you'd need a JOIN to the widget table to get the "title" of the widget

      SELECT   orders.OrderID, orders.OrderDate, widgets.TypeOfWidget
      FROM    Orders  INNER JOIN Widgets ON widgets.WidgetID = orders.WidgetID
      WHERE  OrderID  = 123

.. which would give you

      OrderID | OrderDate | Quantity | TypeOfWidget[
      1 | 3/15/2012 | 3 | Widget A
0
earwig75Author Commented:
Ok, I basically have 1 master table where I am storing all details of my record. The drop down I started this thread about is a list of things that I am populating the drop down with. After a record is created, it can be viewed on a .cfm page and edited again.

This is the query I am using for the drop down:

In my CFC:
 <cffunction name="GetSources"
             returntype="query"
             hint="Get Sources">

  <cfquery datasource="#datasourcea#"
           name="sources">
  SELECT OrderID, Source
  FROM Rtbl_Source
  ORDER BY OrderID
  </cfquery>
  <cfreturn sources>

 </cffunction>

On the page with drop-down:
 <cfinvoke component="origdb"
           method="GetSources"
           returnvariable="sources">

Am I doing this in a way that is not preferred? I believe I am storing the "source" in my master DB as the real value and not the "ID" which I am calling OrderID so I could order them easier on my page.

Thanks again for the help everyone.
0
gdemariaCommented:
>  I believe I am storing the "source" in my master DB as the real value and not the "ID" which I am calling OrderID so I could order them easier on my page

Right, if you are storing the name of the source instead of the ID, you're not doing it correctly.

You want to store the ID of the source.   That way if your client wants to change the source name, it will immediately change everywhere.   This is the concept of "normalization" of a database.

Just another tip...   as your database grows with more tables, a convention to keep things clearer would be to name your ID and your primary column with similar bases..

Table:   Sources
Primary Key:  Source_ID
Name column:  Source    or SourceName

Table:  Category
Primary Key  Category_ID
Name: Category   or CategoryName

Then if when you want to associated these to a product:

Table:  Products
Primary Key:  Product_ID
Name:   ProductName
Category:   Category_ID   ---  foreign key to categories table
Source:   Source_ID   -- foreign key to sources table


That's a general example without knowing your particular design..
0
_agx_Commented:
Am I doing this in a way that is not preferred?

It sounds that way.  Best to avoid duplicating string values in multiple tables because it typically leads to data integrity problems. If you change the value in one table, but not the others, your queries may break because the values no longer match.  Storing the string titles also requires mores storage (for data and indexes), and can be slightly less slower in terms of query speeds. But data integrity problems is the more important reason.

so I could order them easier on my page.

You can still do that with a JOIN. By joining on the numeric id you have access to the columns in both tables and can sort by the "title", instead of the numeric id. Using the earlier example

      SELECT   orders.OrderID, orders.OrderDate, widgets.TypeOfWidget
      FROM    Orders  INNER JOIN Widgets ON widgets.WidgetID = orders.WidgetID
      WHERE  orders.OrderID  = 123
      ORDER BY widgets.TypeOfWidget
0
_agx_Commented:
Oh snap. Didn't see there was already a response to that one ...

<ot>
Really not lovin the new EE layout. One response blurs into the next.  I'm going snow blind, lol.  It's "cute" but the old layout with it's different colors for asker, expert, self was more intuitive. Better UI.
</ot>
0
gdemariaCommented:
> Really not lovin the new EE layout

agreed... there are several step backwards including how the code box is applied and appears..
not many steps forward.  I think they just switched developers and the new team wanted to start over.
0
_agx_Commented:
Even navigating is cumbersome. The lack of back buttons, or remembering menu options, on most screens is bizzare. The old site was too heavy on the ajax imo, but boy I'd kill for it now. Too much "cutesy" stuff and not enough functionality. They need to turn around, because they're going the wrong way ..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.