By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,503 Members | 2,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,503 IT Pros & Developers. It's quick & easy.

if then else not working

P: n/a
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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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 Albertse wrote:
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.

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


--
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.
Jul 21 '05 #2

P: n/a
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 Albertse wrote:
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.

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


--
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.
Jul 21 '05 #3

P: n/a
Gert Albertse wrote:
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
--
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"
Jul 21 '05 #4

P: n/a
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

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

P: n/a
Gert Albertse wrote:
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
--
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.
Jul 21 '05 #6

P: n/a
Gert Albertse wrote:
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.
Jul 21 '05 #7

P: n/a

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").Val ue)="Yes" then
sYes=" selected" 'checked if it were a radio
elseif
trim(RS.Fields("SelectedMultiDisabilityEvent").Val ue)="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

"Gert Albertse" <gj**@sun.ac.za> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

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

Jul 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.