Skip to main content
Inspiring
November 7, 2008
Answered

setting default value in dynamic drop-down menu

  • November 7, 2008
  • 1 reply
  • 1127 views
Hi,

I created a simple drop-down menu that can be used to edit an existing record or to create a new record.

When creating a new record, I'd like the drop-down menu to display "Not specified" by default. Could anyone help me with this?

The "Not specified" option in the drop-down menu should refer to record ID 11 in my database table entitled "names".

Here's what my code looks like so far.

The db queries:

<CFQUERY DATASOURCE="DATA" NAME="get">
SELECT *
FROM names
order by name
</CFQUERY>


<CFQUERY DATASOURCE="DATA" NAME="quo">
SELECT *
FROM quotes
WHERE quoteID = #quoteID#
</CFQUERY>

This part is for the existing database record:

<select name="frn_ID">
<cfoutput query="get">
<option value="#id#"<cfif id is quo.frn_ID> selected</cfif>>#name#</option>
</cfoutput>
</select>

Here is where I'd like the ID with a default value of 11 to be displayed:

<cfelse>
<select name="frn_ID">
<cfoutput query="get">
<option value="#id#">#name#</option>
</cfoutput>
</select>

</cfif>

Thank you for any help with this!

Luke
This topic has been closed for replies.
Correct answer Dan_Bracuk
Step 1 - do some if/else processing to create a variable, let's call it ThisOne, that will be the id of the option you want selected.

Step 2 - Use that variable in the selected attribute of a cfselect tag.

1 reply

Dan_BracukCorrect answer
Inspiring
November 7, 2008
Step 1 - do some if/else processing to create a variable, let's call it ThisOne, that will be the id of the option you want selected.

Step 2 - Use that variable in the selected attribute of a cfselect tag.
Luke10253Author
Inspiring
November 7, 2008
Thank you.

I added this line:
<CFSET ThisOne = 11>

and then edited the drop-down menu to appear like this:

<select name="frn_ID">
<cfoutput query="get">
<option value="#id#" <cfif ThisOne is ID> selected</cfif>>#name#</option>
</cfoutput>
</select>