asp dropdown list with a condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    asp dropdown list with a condition

    Hi, Would anyone know how to populate an asp dropdown with a dependant condition.

    I need this dropdown to select only artists, ie from the authortwo field where in another field, ie extrathree, the word yes is written.



    Code:
      <form method="Post">
          <div>
    <select onChange="window.location='' + this.options[this.selectedIndex].value">
    <OPTION VALUE = 'artists'>&nbsp;artists</Option>
    <OPTION>-----------------------------------------------------</Option>
    <%		
    	Set oRs=Server.CreateObject("adodb.recordset")
    	strSQL = "SELECT DISTINCT AuthorTwo FROM tblGreetingPostCards ORDER BY AuthorTwo"
    	oRs.Open strSQL, conn		
    		
    	Do while not oRs.EOF
    		if Request.Form("GreetingPostCards") = oRs("AuthorTwo") then 'if this is the selected one then display as selected
    			Response.Write "<OPTION VALUE = '" & oRS ("AuthorTwo") & "' SELECTED>"
    			Response.Write oRs("AuthorTwo") & "</Option>"
    			oRs.MoveNext 
    	else
    			Response.Write "<OPTION VALUE = 'http://www.mysite.com/artgallery.asp?AuthorTwo=" & oRs ("AuthorTwo") & "'>&nbsp;"
    			Response.Write oRs("AuthorTwo") & "</Option>"
    			oRs.MoveNext 
    		end if
    	loop		
    	%>
    </SELECT>
    </div>
      </form>
    somehow to combine another condition like


    Code:
         		   		            <%
    If InStr(rsCard("extrathree"),"yes") > 0 Then
    %>
    
    
    
    <I><a href="portfol.asp?authortwo=<%=rsCard("authortwo")%>" title="">info&nbsp;</I><a>
    <%
    Else
    %>
    
    <%
    End If
    %>
    Any help would be great.
    Thanks in advance

    Richard
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

    #2
    Hello fran7,

    I am having a hard time understanding what you are trying to do. I really would like to help you out. Can you give a better example on what you are trying to accomplish? The more detail you can provide in this case is better. No need for posting anymore code just what you wish to accomplish in detail.

    Here is a stab at trying to answer your questing with what I have read above.

    Why don’t you just extend your SQL syntax to add in the condition of the field “extrathree” equaling the word “yes” like this:

    Code:
    SELECT DISTINCT AuthorTwo FROM tblGreetingPostCards WHERE extrathree = ‘yes’ ORDER BY AuthorTwo

    Comment

    • markrawlingson
      Recognized Expert Contributor
      • Aug 2007
      • 346

      #3
      Also Richard, this really has nothing to do with your question, just a helpful observation. I see that you are trying to categorize things within your drop down like so...

      [code=html]
      <OPTION VALUE = 'artists'>&nbsp ;artists</Option>
      <OPTION>-----------------------------------------------------</Option>
      [/code]

      Google <OPTGROUP>

      EG:
      [code=html]
      <select>
      <optgroup label="Artists" >
      <option value="Artist1" >Artist 1</option>
      <option value="Artist2" >Artist 2</option>
      <option value="Artist3" >Artist 3</option>
      </optgroup>
      [/code]

      W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


      Sincerely,
      Mark

      Comment

      • fran7
        New Member
        • Jul 2006
        • 229

        #4
        Dear Mark, Thanks for the reply.

        I hope I can explain better. Basically the dropdown list I have above works fine. But I need it to be populated only by the artists who have " yes" written in another field called "extrathree ".

        Summary
        I have a field called authortwo with all my artists names.
        I have another field extrathree where selective artists have a "yes" written. Those without the "yes" at the moment are left blank but I could fill them with "no" for example.

        So the problem is to populate the dropdown with only those artists names with "yes" written in the field "extrathree "

        Any help would be great.
        Thanks
        Richard

        Comment

        • DrBunchman
          Recognized Expert Contributor
          • Jan 2008
          • 979

          #5
          Hi Richard,

          I think CroCrew already answered your question didn't he? If you change your SQL string to:

          Code:
          strSQL = "SELECT DISTINCT AuthorTwo FROM tblGreetingPostCards WHERE extrathree = 'yes' ORDER BY AuthorTwo"
          Then only the authors with yes next to their name in the column extrathree will be selected and included in your drop down.

          Or is it something else you are after?

          Let us know,

          Dr B

          Comment

          • markrawlingson
            Recognized Expert Contributor
            • Aug 2007
            • 346

            #6
            Yes, CroCrew answered your question accurately fran7 - I was merely making a non-related observation ;)

            Sincerely,
            Mark

            Comment

            • fran7
              New Member
              • Jul 2006
              • 229

              #7
              Dear Mark, I did try that before and it didnt work. must have made a typo. I tried again and bobs your uncle. Works great. Thanks again
              Richard

              Comment

              Working...