if then else not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gert Albertse

    if then else not working

    I retrieve the recordset RS("SelectedMul tiDisabilityEve nt") form a
    table. The data type is text.

    When I run the next code:

    WHILE NOT RS.EOF
    Response.Write RS("SelectedMul tiDisabilityEve nt") & "<br>"
    RS.MOVENEXT
    WEND

    I get the output:
    Yes
    No
    No
    Yes


    But when I modify the code:

    <select name="SelectedM ultiDisabilityE vent" size="1">
    <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
    <option selected value="Yes">Yes </option>
    <option value="No">No</option>
    <%ELSE%>
    <option value="Yes">Yes </option>
    <option selected value="No">No</option>
    <%END IF%>
    </select>

    I get the ouput:
    Yes
    No
    No
    No

    It seems as if it only checks for the first recordset.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Joker

    #2
    Re: if then else not working

    You might want to make sure it is still in the loop like the following
    code is.

    WHILE NOT RS.EOF
    <select name="SelectedM ultiDisabilityE vent" size="1">
    <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
    <option selected value="Yes">Yes </option>
    <option value="No">No</option>
    <%ELSE%>
    <option value="Yes">Yes </option>
    <option selected value="No">No</option>
    <%END IF%>
    </select>
    RS.MOVENEXT
    WEND

    Gert Albertse wrote:
    [color=blue]
    > I retrieve the recordset RS("SelectedMul tiDisabilityEve nt") form a
    > table. The data type is text.
    >
    > When I run the next code:
    >
    > WHILE NOT RS.EOF
    > Response.Write RS("SelectedMul tiDisabilityEve nt") & "<br>"
    > RS.MOVENEXT
    > WEND
    >
    > I get the output:
    > Yes
    > No
    > No
    > Yes
    >
    >
    > But when I modify the code:
    >
    > <select name="SelectedM ultiDisabilityE vent" size="1">
    > <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
    > <option selected value="Yes">Yes </option>
    > <option value="No">No</option>
    > <%ELSE%>
    > <option value="Yes">Yes </option>
    > <option selected value="No">No</option>
    > <%END IF%>
    > </select>
    >
    > I get the ouput:
    > Yes
    > No
    > No
    > No
    >
    > It seems as if it only checks for the first recordset.
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]

    --
    Please do not contact me directly or ask me to contact you directly for
    assistance.

    If your question is worth asking, it's worth posting.

    If it’s not worth posting you should have done a search on
    http://www.google.com/ http://www.google.com/grphp?hl=en&tab=wg&q= or
    http://news.google.com/froogle?hl=en&tab=nf&ned=us&q= before wasting our
    time.

    Comment

    • Joker

      #3
      Re: if then else not working

      One other thing please read my comments in the code as you seem to have
      forgotten that VBscript if statements are only to execute VBscript or
      not to execute Vbscript.

      My only question is, how are you going to handle it having several yes &
      several no selected at the same time?

      <select name="SelectedM ultiDisabilityE vent" size="1">
      <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
      ' execute any VBscript before the else if the statement
      ' is true
      <option selected value="Yes">Yes </option>
      <option value="No">No</option>
      ' No VBscript was found so I wrote everything even if it
      ' wasn't true because it wasn't VBscript.
      '
      ' All the If statement is for is to to execute VBscript or
      ' to not execute VBscript.
      <%ELSE%>
      ' execute any VBscript before the else if the statement
      ' is false
      <option value="Yes">Yes </option>
      <option selected value="No">No</option>
      ' No VBscript was found so I wrote everything even if it
      ' wasn't true because it wasn't VBscript.
      '
      ' All the If statement is for is to to execute VBscript or
      ' to not execute VBscript.
      <%END IF%>
      </select>

      Gert Albertse wrote:
      [color=blue]
      > I retrieve the recordset RS("SelectedMul tiDisabilityEve nt") form a
      > table. The data type is text.
      >
      > When I run the next code:
      >
      > WHILE NOT RS.EOF
      > Response.Write RS("SelectedMul tiDisabilityEve nt") & "<br>"
      > RS.MOVENEXT
      > WEND
      >
      > I get the output:
      > Yes
      > No
      > No
      > Yes
      >
      >
      > But when I modify the code:
      >
      > <select name="SelectedM ultiDisabilityE vent" size="1">
      > <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
      > <option selected value="Yes">Yes </option>
      > <option value="No">No</option>
      > <%ELSE%>
      > <option value="Yes">Yes </option>
      > <option selected value="No">No</option>
      > <%END IF%>
      > </select>
      >
      > I get the ouput:
      > Yes
      > No
      > No
      > No
      >
      > It seems as if it only checks for the first recordset.
      >
      > *** Sent via Developersdex http://www.developersdex.com ***
      > Don't just participate in USENET...get rewarded for it![/color]

      --
      Please do not contact me directly or ask me to contact you directly for
      assistance.

      If your question is worth asking, it's worth posting.

      If it’s not worth posting you should have done a search on
      http://www.google.com/ http://www.google.com/grphp?hl=en&tab=wg&q= or
      http://news.google.com/froogle?hl=en&tab=nf&ned=us&q= before wasting our
      time.

      Comment

      • Bob Barrows [MVP]

        #4
        Re: if then else not working

        Gert Albertse wrote:[color=blue]
        > I retrieve the recordset RS("SelectedMul tiDisabilityEve nt") form a
        > table. The data type is text.
        >
        > When I run the next code:
        >
        > WHILE NOT RS.EOF
        > Response.Write RS("SelectedMul tiDisabilityEve nt") & "<br>"
        > RS.MOVENEXT
        > WEND
        >
        > I get the output:
        > Yes
        > No
        > No
        > Yes
        >
        >
        > But when I modify the code:
        >
        > <select name="SelectedM ultiDisabilityE vent" size="1">
        > <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
        > <option selected value="Yes">Yes </option>
        > <option value="No">No</option>
        > <%ELSE%>
        > <option value="Yes">Yes </option>
        > <option selected value="No">No</option>
        > <%END IF%>
        > </select>
        >
        > I get the ouput:
        > Yes
        > No
        > No
        > No
        >
        > It seems as if it only checks for the first recordset.
        >[/color]

        ? You only have one recordset ... The recordset may contain multiple
        records, but it is only one recordset.

        What happened to the loop? This code as shown will only check the first
        record in your recordset ...
        Why are you building two options for each record?
        If you are looping, why do you expect to have more than one selected option?
        You haven't set the select's multiselect attribute.
        Whether or not you actually are looping, I do not believe you are getting
        the output you say you are getting. With no loop, you should have two
        options as a result of this if statement, not 4. If you are looping, and the
        recordset contains the 4 records you showed as a result of your initial loop
        code, then you should be creating 8 options, not 4.

        Bob Barrows


        --
        Microsoft MVP - ASP/ASP.NET
        Please reply to the newsgroup. This email account is my spam trap so I
        don't check it very often. If you must reply off-line, then remove the
        "NO SPAM"


        Comment

        • Gert Albertse

          #5
          Re: if then else not working

          The code is this but the results still display on the value of the first
          record


          WHILE NOT RS.EOF
          <select name="SelectedM ultiDisabilityE vent" size="1">
          <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
          <option selected value="Yes">yes </option>
          <option value="No">no</option>
          <%ELSE%>
          <option value="Yes">yes </option>
          <option selected value="No">no</option>
          <%END IF%>
          </select>
          RS.MOVENEXT
          WEND



          *** Sent via Developersdex http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • Bob Barrows [MVP]

            #6
            Re: if then else not working

            Gert Albertse wrote:[color=blue]
            > The code is this but the results still display on the value of the
            > first record
            >
            >
            > WHILE NOT RS.EOF
            > <select name="SelectedM ultiDisabilityE vent" size="1">
            > <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
            > <option selected value="Yes">yes </option>
            > <option value="No">no</option>
            > <%ELSE%>
            > <option value="Yes">yes </option>
            > <option selected value="No">no</option>
            > <%END IF%>
            > </select>
            > RS.MOVENEXT
            > WEND
            >
            >
            >[/color]

            So you wish to create multiple dropdown boxes all having the same name?
            Isn't it obvious that each dropdown will only contain options generated from
            a single record in your recordset? Perhaps you should clarify what your
            intended results are ...

            Bob Barrows
            --
            Microsoft MVP -- ASP/ASP.NET
            Please reply to the newsgroup. The email account listed in my From
            header is my spam trap, so I don't check it very often. You will get a
            quicker response by posting to the newsgroup.


            Comment

            • Dave Anderson

              #7
              Re: if then else not working

              Gert Albertse wrote:[color=blue]
              > But when I modify the code:
              >
              > <select name="SelectedM ultiDisabilityE vent" size="1">
              > <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
              > <option selected value="Yes">Yes </option>
              > <option value="No">No</option>
              > <%ELSE%>
              > <option value="Yes">Yes </option>
              > <option selected value="No">No</option>
              > <%END IF%>
              > </select>
              >
              > I get the ouput:
              > Yes
              > No
              > No
              > No[/color]

              It would appear your problems go far beyond conditionals, as your output has
              no SELECT elements, no OPTION elements, and suggests unrequested looping
              behavior.



              --
              Dave Anderson

              Unsolicited commercial email will be read at a cost of $500 per message. Use
              of this email address implies consent to these terms. Please do not contact
              me directly or ask me to contact you directly for assistance. If your
              question is worth asking, it's worth posting.


              Comment

              • TomB

                #8
                Re: if then else not working


                Since the choices are Yes or No, how about radio buttons? There (IMO)
                faster to pick from.I would do this......

                <%

                Do While Not RS.EOF
                sYes=""
                sNo=""
                if
                Trim(RS.Fields( "SelectedMultiD isabilityEvent" ).Value)="Yes" then
                sYes=" selected" 'checked if it were a radio
                elseif
                trim(RS.Fields( "SelectedMultiD isabilityEvent" ).Value)="No" then
                sNo=" selected" 'checked if it were a radio
                end if
                %>
                <select
                name="<%=RS.Fie lds("UniqueEven tName").Value)% >">
                <option
                value="Yes"<%=s Yes%>>Yes</option>
                <option
                value="No"<%=sN o%>>No</option>
                </select>
                <%
                RS.MoveNext
                Loop
                %>

                One other suggestion...I' d store a boolean value in my
                SelectedMultiDi sabilityEvent Field, or an integer if more than two options
                were needed.
                My guess is your original field value has a space in it that you can't see
                when you just response.write it. Try Doing what you did with some text
                around it.... I usually do something like this.

                <%
                Do While not RS.EOF
                Response.write "TOM" & RS.Fields("Fiel dName").Value & "TOM<br>" 'I'm
                extremely vain.
                RS.MoveNext
                Loop
                %>
                Thus, I can see if there's any spaces printing out.

                TomB

                "Gert Albertse" <gjja@sun.ac.za > wrote in message
                news:%23vvB1j1t EHA.1400@TK2MSF TNGP11.phx.gbl. ..[color=blue]
                > I retrieve the recordset RS("SelectedMul tiDisabilityEve nt") form a
                > table. The data type is text.
                >
                > When I run the next code:
                >
                > WHILE NOT RS.EOF
                > Response.Write RS("SelectedMul tiDisabilityEve nt") & "<br>"
                > RS.MOVENEXT
                > WEND
                >
                > I get the output:
                > Yes
                > No
                > No
                > Yes
                >
                >
                > But when I modify the code:
                >
                > <select name="SelectedM ultiDisabilityE vent" size="1">
                > <%IF RS("SelectedMul tiDisabilityEve nt") = "Yes" THEN%>
                > <option selected value="Yes">Yes </option>
                > <option value="No">No</option>
                > <%ELSE%>
                > <option value="Yes">Yes </option>
                > <option selected value="No">No</option>
                > <%END IF%>
                > </select>
                >
                > I get the ouput:
                > Yes
                > No
                > No
                > No
                >
                > It seems as if it only checks for the first recordset.
                >
                > *** Sent via Developersdex http://www.developersdex.com ***
                > Don't just participate in USENET...get rewarded for it![/color]


                Comment

                Working...