7 Replies Latest reply: May 15, 2012 10:56 AM by BKBK RSS

    Simple Default value for drop down menu

    jamie61880 Community Member

      Does anyone know why this would be happening?

            I have a drop down menu on my Quality page for PDF_Creation_Doc_Control_Approval_Initials (I’ll shorten this to Doc Initials so you know what I’m talking about). Right now it is defaulted to be blank if nothing has been chosen for it yet. If initials are chosen, the initials will display when the page is loaded. The problem I’m having is that I want the “None” option to display as the default if the SW_Model_Only is 1.  I’m just trying to get “None” to be the default for these. The code below does work if I hit the refresh button, but it does not work when I just click on the Quality link. Why would this be? How do I fix it? Below is the code for this drop down on the Quality Page. I added this If Statement:

       

      <cfif SW_Model_Only Is 1>

      <option value="None"></option>

      <cfelse>

      <option value=""></option>

      </cfif>

       

           The option value="" was already there.

       

       

      <cfset PDFCreationDocControlInitials = DocumentationSearch.PDF_Creation_Doc_Control_Initials>

      <td align="center">

      <cfif Quality_Mgr_Initials Is Not "" and Quality_Mgr_Initials EQ cookie.UserInitials<!--- and SW_Model_Only Is 0 --->>

      <select name="PDF_Creation_Doc_Control_Approval_Initials#ItemID#" id="PDF_Creation_Doc_Control_Approval_Initials#ItemID#">

      <cfif SW_Model_Only Is 1>

      <option value="None"></option>

      <cfelse>

      <option value=""></option>

      </cfif>

      <cfloop query="ShowInitials">

      <option value="#Initials#"

      <cfif #Initials# EQ PDFCreationDocControlInitials>selected</cfif>>#Initials#</option>

      </cfloop>

      </select>

      <cfelse>

       

      </cfif>

        </td>

       

      Thanks for your help.

      Andy

        • 1. Re: Simple Default value for drop down menu
          BKBK MVP

          Couldn't it be simplified to something like this?

           

          <cfset optionDefault = "none">

          <cfif SW_Model_Only NEQ 1>

              <cfset optionDefault = "">

          </cfif>

          <option value="#optionDefault#"></option>

          <cfloop query="ShowInitials">

          <option></option>

          </cfloop>

          • 2. Re: Simple Default value for drop down menu
            jamie61880 Community Member

            BKBK,

                No, this did not do anything. Any other ideas?

            Andy

            • 3. Re: Simple Default value for drop down menu
              BKBK MVP

              jamie61880 wrote:

               

              BKBK,

                  No, this did not do anything. Any other ideas?

              Then I should ask you to clarify what you mean by a "click on the Quality link".

              • 4. Re: Simple Default value for drop down menu
                jamie61880 Community Member

                There is a link that I have called "Quality Items". There are 2 ways to get the page updated. Either click the Refresh button, or click on this link. Clicking on the link does not allow "None" to display in the drop down menu. But if I was on this Quality page already and updated my code, and clicked the Refresh button, it puts "None" into the drop down as the default. Why would it work with clicking the Refresh button, but not clicking on the link?

                • 5. Re: Simple Default value for drop down menu
                  BKBK MVP

                  jamie61880 wrote:

                   

                  There is a link that I have called "Quality Items". There are 2 ways to get the page updated. Either click the Refresh button, or click on this link. Clicking on the link does not allow "None" to display in the drop down menu. But if I was on this Quality page already and updated my code, and clicked the Refresh button, it puts "None" into the drop down as the default. Why would it work with clicking the Refresh button, but not clicking on the link?

                   

                  It could be that, clicking on the link returns a cached copy of the page. To prevent caching, add the following headers at the top of the page:

                   

                  <cfheader name="cache-control" value="no-cache,no-store,must-revalidate">

                  <cfheader name="pragma" value="no-cache">

                  <cfheader name="expires" value="#getHttpTimeString(now())#">

                  • 6. Re: Simple Default value for drop down menu
                    jamie61880 Community Member

                    BKBK,

                        I put this code at the top of the page and the drop down does not have the "None" being the default at all now. So this might have answered the caching thing, but I still don't know how to make "None" be the default when the page loads. How do you make a word in a drop down menu be the default when the drop down menu is being populated dynamically from a database?

                     

                    Andy

                    • 7. Re: Simple Default value for drop down menu
                      BKBK MVP

                      By default, the first option is the one selected in a drop-down. As I said, something like this should work:

                       

                      <cfset optionDefault = "none">

                      <cfif SW_Model_Only NEQ 1>

                          <cfset optionDefault = "">

                      </cfif>

                       

                      <cfoutput>

                      <select name="PDF_Creation_Doc_Control_Approval_Initials#ItemID#" id="PDF_Creation_Doc_Control_Approval_Initials#ItemID#">

                      <option value="#optionDefault#">#optionDefault#</option>

                      <cfloop query="ShowInitials">

                      <option value="#initials#">#initials#</option>

                      </cfloop>

                      </select>

                      </cfoutput>