Skip to main content
Participating Frequently
June 27, 2006
Question

Drop-down menu with both static and dinamic data

  • June 27, 2006
  • 8 replies
  • 876 views
Hi to everyone!!!

Please is very important if someone could answer me fast !

This is the code:
...
<cfquery name="getCountry" datasource="db">
SELECT Country
FROM Table
ORDER BY Country
</cfquery>
...
<select name="menu">
<option value="staticOption.cfm">America</option>
<cfoutput query="getCountry">
<option value="dinamicOption.cfm">#Country#</option>
</cfoutput>
</select>

The output will be:

America
(here is a hole)
Australia
Cuba
Ecuador
Italia
...

I don't know why the query produces a list of Countries (or other data) with a hole in top of the list. My problem is that I have to add the first option in the menu, that is not a result of a query but only a static option, cause I want to have the list ordered. And I want that the first selected option to be empty.
So I want to have this:

first selected option empty
America
Australia
Cuba
Ecuador
Italia
...

Please can someone tell me what to do?

thanks a lot
    This topic has been closed for replies.

    8 replies

    bimbicaAuthor
    Participating Frequently
    June 27, 2006
    I found the solution (have to thank you :) ): now there is no hole. Probably the problem was in the query. But in the other menu (that one with languages, I posted before) I had to add this code in the query

    WHERE FornitoriEsteri.IdScuola=TCorsi.IdScuola AND Lingua NOT IN ('')

    (even if it does nothing different in the query) to have no blank spaces.
    Why? Maybe the recordset have an empty record? And if it so, why happens only in the menus and not in a table?

    Inspiring
    June 27, 2006
    I've done many dynamic drop downs with mixed static and dynamic outputs with no issue ever resulting in a blank option or space.

    Have you maybe thought of trying CFFORM and CFSELECT? We use both SELECT and CFSELECT dynamically and mixed w/o issues.




    You could attach a file to the post with the screenshot if you like, usually works best with ZIP files

    Additionally, could you include a copy of the generated source as a TXT file. Not the CF document, but the generated output. I want to run it through an analyzer for np-characters.

    EDIT: Sorry, it appears they dropped that ability now. We used to be able to attach files.
    Inspiring
    June 27, 2006
    Are any of these countries in the DB?
    FRANCE,GERMANY,NEW ZEALAND,INGHILTERRA,AU PAIR,STAGE,CUBA,ECUADOR

    I suspect that may be the issue if they are.

    You will know for certain if you comment out that section of code and everything works properly.

    If it is the issue, then in your QUERY specify a WHERE clause that will bypass those countries
    bimbicaAuthor
    Participating Frequently
    June 27, 2006
    Yes, those coutries (errors) are in the db and I wanted to bypass them using that cfcase, cause I don't know how to make a right where clause.
    I've alredy commented it and happend nothing different from before. Always the same result. I'm sorry but online are only the static version of pages. However I made another menu with another query from another column of the db:
    <cfquery datasource="dbsDati" name="getLingue">
    SELECT DISTINCT Lingua
    FROM FornitoriEsteri,TCorsi
    WHERE FornitoriEsteri.IdScuola=TCorsi.IdScuola
    </cfquery>

    <cfoutput query="getLingue">
    <option value="dettaglio_lingue.cfm?idLingua=#Lingua#">#Lingua#</option>
    </cfoutput>

    This is without cfswitch and makes the same hole at the top of the list.

    Can you tell me how to make a where clause, please?

    thank, thank, thank
    Inspiring
    June 27, 2006
    Sorry - for some reason I could not access Adobe.com for about the last half hour


    Starting with the query, try something like this:

    SELECT DISTINCT Paese
    FROM FornitoriEsteri,TCorsi
    WHERE FornitoriEsteri.IdScuola=TCorsi.IdScuola
    AND Paese NOT IN ('FRANCE','GERMANY','NEW ZEALAND','INGHILTERRA','AU PAIR','STAGE','CUBA','ECUADOR')

    This should choose all distinct countries besides the ones in that list

    Then your output should be as before w/o any switches.
    <CFOUTPUT query="MyQuery">
    <option value="dettaglio_paesi.cfm?idPaese=#MyQuery.Paese#">#CapFirst(MyQuery.Paese)#</option>
    </CFOUTPUT>



    BTW, What is CapFirst? It does not appear to be a CF tag or function in MX701, so is it some custom thing that DW created? Maybe that is what is doing it?

    Does it work w/o it?

    <CFOUTPUT query="MyQuery">
    <option value="dettaglio_paesi.cfm?idPaese=#MyQuery.Paese#">#MyQuery.Paese#</option>
    </CFOUTPUT>
    bimbicaAuthor
    Participating Frequently
    June 27, 2006
    Hi Frank,

    I didn't understand very good what you mean...but perhaps is better if i write the real code :

    for the query:
    SELECT DISTINCT Paese
    FROM FornitoriEsteri,TCorsi
    WHERE FornitoriEsteri.IdScuola=TCorsi.IdScuola

    for the output:
    <select name="ScegliPaese" class="testo_min" id="ScegliPaese" onChange="">
    <option value="dettaglio_america_centrale.cfm">America Centrale</option>
    <cfoutput query="getPaesi">
    <CFSWITCH EXPRESSION="#getPaesi.Paese#">
    <CFCASE VALUE="FRANCE,GERMANY,NEW ZEALAND,INGHILTERRA,AU PAIR,STAGE,CUBA,ECUADOR" DELIMITERS=",">
    </CFCASE>

    <CFDEFAULTCASE>
    <option value="dettaglio_paesi.cfm?idPaese=#Paese#">#CapFirst(Paese)#</option>
    </CFDEFAULTCASE>
    </CFSWITCH>
    </CFOUTPUT>
    </select>

    Maybe the problem is the case value for the coutries that I don't want to display and make a hole. But when I used the same expression to full a table, then weren't holes. I'm only beginner, so tell me please. :)
    Inspiring
    June 27, 2006
    Instead of doing a query output for the options, what if you loop through, say 1-10 in a CFLOOP and create a dynamic menu that way?

    Do you still see a space/blank entry?

    I realize this would not actually create the list of countries, but it should create a dynamic dropdown with America + the numbers 1-10 as options for testing purposes.

    If this works ok, and the query does not, then it has to be something in the DB output.

    Is there any way I could see the page online?



    As for the countries being ordered, if you do not specify ordering, then it will output as it is found in the DB, so they could simply be in order already.


    bimbicaAuthor
    Participating Frequently
    June 27, 2006
    Hi Glen!! Thank you for responding me! :)

    So it is:

    I saw the source code of the generated page ande there is no blank option that could be a reson for having that hole.

    But I saw better my code in the application and there is not GROUP BY nether ORDER BY (the first time I've looked wrong) in the query. But in the generated page the counties appear to be ordered (?)!

    i don't know if the problem lies in the coldfusion or simply in the configuration of the menu. The fact is that when I make a dinamically generated menu, there is a blank option selected first (without I have asked for it), and if I add the first option static, it becomes as I have already wrote.

    I made another test: if I make all static menu (I'm using Dreamweaver), then i must add a blank option if I want to have one. With dinamic it comes without asking. Mah...

    I have to resolve this, it is very important.
    Inspiring
    June 27, 2006
    WHERE length(Country)>1 or maybe a distinct(Country)...it looks like something in the table maybe goofy.

    SELECT Country
    FROM Table
    WHERE length(Country)>1
    ORDER BY Country

    Or

    SELECT distinct(Country)
    FROM Table
    ORDER BY Country

    Frank
    Inspiring
    June 27, 2006
    There is no reason it would produce a balnk entry unless you are actually grouping (not ordering as shown) and it found nothing for America as a Group.

    HTML will not put in arbitary spaces, so that either means you have a blank entry in your database, for which it placed a blank option, or you are actually trying to group.

    If your code is exactly as in your app, it shouldn't be grouping, so then your investigation lies in figuring out WHY it is showing a blank option.

    If you look at the surce code of the page that is generated, is there a blank option showing in that select field?