if then else not working

G

Gert Albertse

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

When I run the next code:

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

I get the output:
Yes
No
No
Yes


But when I modify the code:

<select name="SelectedMultiDisabilityEvent" size="1">
<%IF RS("SelectedMultiDisabilityEvent") = "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.
 
J

Joker

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

WHILE NOT RS.EOF
<select name="SelectedMultiDisabilityEvent" size="1">
<%IF RS("SelectedMultiDisabilityEvent") = "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 said:
I retrieve the recordset RS("SelectedMultiDisabilityEvent") form a
table. The data type is text.

When I run the next code:

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

I get the output:
Yes
No
No
Yes


But when I modify the code:

<select name="SelectedMultiDisabilityEvent" size="1">
<%IF RS("SelectedMultiDisabilityEvent") = "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.

--
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.
 
J

Joker

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="SelectedMultiDisabilityEvent" size="1">
<%IF RS("SelectedMultiDisabilityEvent") = "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 said:
I retrieve the recordset RS("SelectedMultiDisabilityEvent") form a
table. The data type is text.

When I run the next code:

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

I get the output:
Yes
No
No
Yes


But when I modify the code:

<select name="SelectedMultiDisabilityEvent" size="1">
<%IF RS("SelectedMultiDisabilityEvent") = "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.

--
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.
 
B

Bob Barrows [MVP]

Gert said:
I retrieve the recordset RS("SelectedMultiDisabilityEvent") form a
table. The data type is text.

When I run the next code:

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

I get the output:
Yes
No
No
Yes


But when I modify the code:

<select name="SelectedMultiDisabilityEvent" size="1">
<%IF RS("SelectedMultiDisabilityEvent") = "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.

? 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
 
G

Gert Albertse

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


WHILE NOT RS.EOF
<select name="SelectedMultiDisabilityEvent" size="1">
<%IF RS("SelectedMultiDisabilityEvent") = "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
 
B

Bob Barrows [MVP]

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


WHILE NOT RS.EOF
<select name="SelectedMultiDisabilityEvent" size="1">
<%IF RS("SelectedMultiDisabilityEvent") = "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

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
 
D

Dave Anderson

Gert said:
But when I modify the code:

<select name="SelectedMultiDisabilityEvent" size="1">
<%IF RS("SelectedMultiDisabilityEvent") = "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 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.
 
T

TomB

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("SelectedMultiDisabilityEvent").Value)="Yes" then
sYes=" selected" 'checked if it were a radio
elseif
trim(RS.Fields("SelectedMultiDisabilityEvent").Value)="No" then
sNo=" selected" 'checked if it were a radio
end if
%>
<select
name="<%=RS.Fields("UniqueEventName").Value)%>">
<option
value="Yes"<%=sYes%>>Yes</option>
<option
value="No"<%=sNo%>>No</option>
</select>
<%
RS.MoveNext
Loop
%>

One other suggestion...I'd store a boolean value in my
SelectedMultiDisabilityEvent 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("FieldName").Value & "TOM<br>" 'I'm
extremely vain.
RS.MoveNext
Loop
%>
Thus, I can see if there's any spaces printing out.

TomB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top