Solved

If drop down box is empty hide.

Posted on 2004-04-14
5
409 Views
Last Modified: 2012-06-27
I am using the code below to fill a select box  but if I have no values I would like the select box to not show.  I would also like the submit button (Next) to hide as well.  How do I do this?



      '*****************************************************************
      '* Step 2: Get the Store the User would like to view
      '*****************************************************************

ElseIf Request.Form("FormAction") = "Step2" Then



      %>

      <form action="ar_home_documents.asp" method="post" name="frmDisplay">
      <input type="hidden" name="FormAction" value="Step3">
      <input type="hidden" name="txtDivisionName2" value="<%=Request.Form("txtdivision2")%>">
      <input type="hidden" name="txtFirstFolderName" value="<%=Request.Form("Folders")%>">
      <% response.write "<font color='Black'><STRONG><EM>Select Subject: </font></EM></font></STRONG><BR>"

            Dim strFolder
            Set strFolder = Request.Form("Folders")
            set txtFirstFolderName = strFolder
            'Response.Write "txtDivisionName = " & strfolder & ""
            
                                          objPath = Server.MapPath("AR_documentation/" & strFolder)
                                          Set objFSO = CreateObject("Scripting.filesystemObject")
                                          Set objfolder1 = objFSO.Getfolder(objPath)
                                          Set objFolder2 = objfolder1.Subfolders
                                          selectbox="<select name=folders2>"
                                                For Each f1 in objFolder2
                                                selectbox=selectbox & "<option>" & f1.name
                                                Next
                                          selectbox=selectbox &"</select>"
                                          response.write selectbox
                                          set objfolder1=Nothing
                                          set objFSO = Nothing
                                          set objFolder2 = nothing
                                          

                  dim objPath2, fso, folder
                  'Set fso = Server.CreateObject("Scripting.FileSystemObject")
                  objPath2 = Server.MapPath("AR_documentation\" & strFolder)
                  Set FSO = CreateObject("Scripting.filesystemObject")
                  Set folder = FSO.Getfolder(objPath2)
                  'This works for the C Drive.
                  'Set folder = fso.GetFolder("C:\Inetpub\wwwroot\aresearch\AR_documentation\" & strFolder & "")

      %>
      <INPUT name=btnSubmit type=submit value="  Next >">
      <%
      
      
      
      Response.Write "<BR>"
      Response.Write "<BR>"
      Response.Write "<BR>"

      response.write "<STRONG><EM><font color='Black'>Select File: </EM></STRONG></font><br>"
      %>
      <SELECT id=select1 name=select1 onChange="javascript:window.open(this.value,'groovywindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=' + WinHeight + 'width=' + WinWidth + 'copyhistory=no')">
0
Comment
Question by:flfmmqp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 11

Accepted Solution

by:
Slimshaneey earned 500 total points
ID: 10825427
Add a variable to say that there are variables in the loop like this:

objPath = Server.MapPath("AR_documentation/" & strFolder)
                                   Set objFSO = CreateObject("Scripting.filesystemObject")
                                   Set objfolder1 = objFSO.Getfolder(objPath)
                                   Set objFolder2 = objfolder1.Subfolders
                                   selectbox="<select name=folders2>"
Dim HasVals
HasVals = False
                                        For Each f1 in objFolder2
                                        selectbox=selectbox & "<option>" & f1.name
                                           HasVals = True
                                        Next
                                   selectbox=selectbox &"</select>"
                                   response.write selectbox
                                   set objfolder1=Nothing
                                   set objFSO = Nothing
                                   set objFolder2 = nothing

Then check the value when writing the select and the submit:

<%
If HasVals then
%>
<SELECT id=select1 name=select1 onChange="javascript:window.open(this.value,'groovywindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=' + WinHeight + 'width=' + WinWidth + 'copyhistory=no')">

<%End if%>
0
 
LVL 3

Expert Comment

by:jmaddalone
ID: 10825455
  '*****************************************************************
     '* Step 2: Get the Store the User would like to view
     '*****************************************************************

ElseIf Request.Form("FormAction") = "Step2" Then



     %>

     <form action="ar_home_documents.asp" method="post" name="frmDisplay">
     <input type="hidden" name="FormAction" value="Step3">
     <input type="hidden" name="txtDivisionName2" value="<%=Request.Form("txtdivision2")%>">
     <input type="hidden" name="txtFirstFolderName" value="<%=Request.Form("Folders")%>">
     <% response.write "<font color='Black'><STRONG><EM>Select Subject: </font></EM></font></STRONG><BR>"

          Dim strFolder
         
         '******************
          Dim selectbox
          selectbox = ""
          '******************
         
         Set strFolder = Request.Form("Folders")
          set txtFirstFolderName = strFolder
          'Response.Write "txtDivisionName = " & strfolder & ""
         
                                   objPath = Server.MapPath("AR_documentation/" & strFolder)
                                   Set objFSO = CreateObject("Scripting.filesystemObject")
                                   Set objfolder1 = objFSO.Getfolder(objPath)
                                   Set objFolder2 = objfolder1.Subfolders
                                   selectbox="<select name=folders2>"
                                        For Each f1 in objFolder2
                                        selectbox=selectbox & "<option>" & f1.name
                                        Next
                                   selectbox=selectbox &"</select>"
                                   set objfolder1=Nothing
                                   set objFSO = Nothing
                                   set objFolder2 = nothing
                                   

               dim objPath2, fso, folder
               'Set fso = Server.CreateObject("Scripting.FileSystemObject")
               objPath2 = Server.MapPath("AR_documentation\" & strFolder)
               Set FSO = CreateObject("Scripting.filesystemObject")
               Set folder = FSO.Getfolder(objPath2)
               'This works for the C Drive.
               'Set folder = fso.GetFolder("C:\Inetpub\wwwroot\aresearch\AR_documentation\" & strFolder & "")
            
            '******************
            if  selectbox <> "" then
                  response.write selectbox
                 %>
                 <INPUT name=btnSubmit type=submit value="  Next >">
                 <%
             end if
            '******************    
     
     
     Response.Write "<BR>"
     Response.Write "<BR>"
     Response.Write "<BR>"

     response.write "<STRONG><EM><font color='Black'>Select File: </EM></STRONG></font><br>"
     %>
     <SELECT id=select1 name=select1 onChange="javascript:window.open(this.value,'groovywindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=' + WinHeight + 'width=' + WinWidth + 'copyhistory=no')">
0
 
LVL 7

Expert Comment

by:ramesh12
ID: 10825466
Use a simple counter and if the counter value is set then write the selest otherwise leave it llike this

dim counter
counter=0
                                        For Each f1 in objFolder2
                                        counter=counter+1
                                        selectbox=selectbox & "<option>" & f1.name
                                        Next


if counter>0 then
response.write selectbox
end if


and then with submit button use respose.write  after this

               Set FSO = CreateObject("Scripting.filesystemObject")
               Set folder = FSO.Getfolder(objPath2)
               'This works for the C Drive.
               'Set folder = fso.GetFolder("C:\Inetpub\wwwroot\aresearch\AR_documentation\" & strFolder & "")

like this

if counter>0 then
response.write "<INPUT name=btnSubmit type=submit value='  Next >'>"
end if

0
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10825490
FOllowing on from the earlier comment, you can hide the submit also like this:
If HasVals then
  %>
     <INPUT name=btnSubmit type=submit value="  Next >">
     <%
End if
     
0
 

Author Comment

by:flfmmqp
ID: 10825587
Some times the answer is so simple you just have a hard time figuring it out in your own code mess.  Thanks for the help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Asp in server side with Mssql Server 7 4 34
window close link 7 36
SP converting date time to date and time separately 2 20
JS to redirect to prev page 8 25
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question