0

I am going back to a simple drop down form that when selected. It populates the next selections below it. So a Category say Fruit... Then the SubCategory is autopopulated in the select with "Apple, Orange, Bananna, etc" But I'd like the select field searchable. I know it can be done, but I need to preserve the option value which is a unique identifier. I can't seem to figure out how to make the select searchable. So starting back at scratch. Unless anyone has better ideas on how to do a searchable select field. That then populates another select field that is searchable.

So both select fields need to be searchable, yet preserve the option value too.

Perhaps there is a newer easier way?

    <cfquery name="catlist" datasource="ds_source">
    select * from ecat
    order by catname
    </cfquery>
    <cfquery name="sublist" datasource="ds_source">
    select * from esubcat
    order by subcatname
    </cfquery>

    <script language="JavaScript1.2"> 
    function whichCategory(obj){ 
                switch (obj.ecat.selectedIndex){ 
                
                <cfoutput query=catlist group=catname>
                
                case #catlist.currentrow#:
                <cfquery name="sublist" datasource="ds_source">
                select * from esubcat
                where ecatid = '#catlist.ecatid#'
                order by subcatname
                </cfquery>
                <cfoutput>
                obj.esubcat.length=#sublist.recordcount# 
                </cfoutput>
                <cfset cr = 0>
                <cfloop query=sublist>
                <cfoutput>
                obj.esubcat.options[#cr#].value="#esubcat#" 
                obj.esubcat.options[#cr#].text="#subcatname#"
                </cfoutput>
                <cfset cr = cr +1>
                </cfloop>
                break; 
                </cfoutput> 
                
                } 
           } 
        </script> 

    Category: <br>
    <select name="ecat" onchange="whichCategory(this.form)"> 
   <option value="">- Select Category -</option> 
    <cfoutput query=catlist group=catname>
    <option value="#ecatid#">#catname#</option> 
    </cfoutput>
    </select> 

    <br>
    SubCategory: <br>
    <select name="esubcat" onchange="whichCategory(this.form)"> 
         <option value="">First Select Category Above</option> 
      </select> 

I found this online. And it works for the search. But it deactivates the second selection of things.

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/js/standalone/selectize.min.js" integrity="sha256-+C0A5Ilqmu4QcSPxrlGpaZxJ04VjsRjKu+G82kl5UJk=" crossorigin="anonymous"></script>

      <script language="JavaScript">
        $(document).ready(function () {
        $('select').selectize({
        sortField: 'text'
       });
      });
      </script>
Merle_the_Pearl
  • 1,391
  • 3
  • 18
  • 25
  • 1
    Whenever I enter a `select` control on a web page, if I start typing something the first available selection that matches what I typed appears. To me, that means the `select` control is searchable. If you have a different objective in mind, please edit your question to explain what you mean by `searchable`. – Dan Bracuk Oct 26 '21 at 16:42
  • 2
    @Merle do you mean a `datalist` ? – TRose Oct 26 '21 at 18:20
  • 1
    Does this answer your question? [Creating a select box with a search option](https://stackoverflow.com/questions/18796221/creating-a-select-box-with-a-search-option) – Adrian J. Moreno Oct 26 '21 at 19:20
  • Yes I believe there is a CSS Datalist, but I do not believe you can pass a different value than the name - ie: IDKEY of value="33FFG">Banana – Merle_the_Pearl Oct 28 '21 at 17:13
  • Dan yes... by default - the select does do that. But its just first letter searchable I believe. So if I'm looking for FORD... as soon as I type F - the F's show up... But as soon as you type O.. the O's show up. It's subtle but aggravates a few people. – Merle_the_Pearl Oct 28 '21 at 17:15
  • @Merle_the_Pearl you can pass in custom values and access them. https://stackoverflow.com/questions/40214704/how-to-get-data-value-in-data-list/57608607 – TRose Oct 28 '21 at 23:38

0 Answers0