Skip to main content
Known Participant
May 8, 2008
Question

cfselect selected=

  • May 8, 2008
  • 4 replies
  • 778 views
I'm using the code below for my form, so the form is pre-populated with data passed from a 'update' link. However, if I then use the drop down, it shows the selected option (from the data) but also shows that option again as an option in the dropdown...is there a way to not duplicate the option in the dropdown?

many thanks in advance

code:
<cfselect name="status" >
<option selected="#formfiller.status#">#formfiller.status#</option>
<option value = "Pending">Pending</option>
<option value = "Won">Won</option>
</cfselect>
    This topic has been closed for replies.

    4 replies

    May 8, 2008
    quote:

    Originally posted by: simbull
    I'm using the code below for my form, so the form is pre-populated with data passed from a 'update' link. However, if I then use the drop down, it shows the selected option (from the data) but also shows that option again as an option in the dropdown...is there a way to not duplicate the option in the dropdown?

    many thanks in advance

    code:
    <cfselect name="status" >
    <option selected="#formfiller.status#">#formfiller.status#</option>
    <option value = "Pending">Pending</option>
    <option value = "Won">Won</option>
    </cfselect>


    For starters, it looks like you are entering in your value of formfiller.status into the selected="", you should have this in the Value="" attribute... if this contains the value of "Pending" or "Won" (which would explain why you have duplicate data) then you can go ahead and remove this line.

    Since you have the options hard coded, you can do something like this to have the option already selected, and avoid the duplicate option.

    <cfselect name="status" >
    <option value = "Pending" <cfif formfiller.status EQ 'Pending'>selected</cfif>>Pending</option>
    <option value = "Won" <cfif formfiller.status EQ 'Won'>selected</cfif>>Won</option>
    </cfselect>

    Hopefully this is what you were looking for.
    Known Participant
    May 8, 2008
    yes cf_output, thats looks like it. many thanks. I shall give that a go.
    Known Participant
    May 8, 2008
    could you possible elaborate please as to how I would use that function?

    thanks
    Inspiring
    May 8, 2008
    quote:

    Originally posted by: simbull
    could you possible elaborate please as to how I would use that function?

    thanks

    Usage is described in the cfml reference manual. If you don't have one, the internet does.
    Inspiring
    May 8, 2008
    No, that's an option tag.
    Inspiring
    May 8, 2008
    cfselect has a selected attribute that might work for your particular situation.
    Known Participant
    May 8, 2008
    Thanks for the reply Dan, but isn't that what i am already using with:

    <option selected="#formfiller.status#">#formfiller.status#</option>

    cheers