0

I currently have a CFSELECT list that binds to a CFC to get the list of data.

Here is my CFSELECT

 <cfselect name="descriptionDD4" 
     id="descriptionDD4" 
     value="description" 
     bind="cfc:cfcs.menudata.getData()" 
     bindonload="true" />

Here is my CFC

<!---First Slect Box --->
<cffunction name="getData" access="remote" returntype="query">
    <cfoutput>
    <!--- Function to get data from datasource --->
    <cfquery name="data" datasource="#datasource#">
    select description
    from service_descriptions
    order by description
    </cfquery>
    </cfoutput>

    <!--- Return results --->
    <cfreturn data>
</cffunction>

What I would like to do is add a static option to the top of this list that is a hyperlink. But what I've found is that if I use the bind command, I cannot add any options to my list as it will throw a CF error.

Is there any way to keep my current configuration but add a hyperlink option to this list.?

Leigh
  • 28,765
  • 10
  • 55
  • 103
Brian Fleishman
  • 1,237
  • 3
  • 21
  • 43
  • return the option from the `getData()` call. then add an `onchange` handler and if the first item is selected, go to the target destination URL. – Sean Coyne Aug 26 '14 at 16:32
  • Thanks. I've came up with a similar solution in my googles. I'll post my answer. – Brian Fleishman Aug 26 '14 at 16:50
  • Nothing to do with your issue, but a couple tips: 1) All function local variables should be `var/local` scoped. That includes query names ie `data` 2) There is no need to wrap the `cfquery` in `cfoutput` tags. Any `#variables#` within the `cfquery` tags will be evaluated automatically. – Leigh Aug 26 '14 at 17:58

1 Answers1

0

I came up with a way of doing it by using this script:

<!---Script to pop modal if "add New" is selected --->    
        <script>
            $(function(){
              // bind change event to select
              $('##descriptionDD3').on('change', function () {
                  var option = $( "##descriptionDD3 option:selected" ).text(); // get selected value
                    if (option == 'ADD NEW') { // require a URL
                  $('##addDescriptionsLink').trigger('click'); // redirect
                 }
                  return false;
              });
            });
        </script>

My script will check if the option "ADD NEW" is chosen and then it will launch a link that I have defined on my page.

Brian Fleishman
  • 1,237
  • 3
  • 21
  • 43