473,395 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

if then else not working

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
7 2505
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
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
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
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
4
by: Simon | last post by:
Hi there I know I should be able to do this, but I'm stuck! I am trying to build a table that forms from cats being pulled from a DB. The table will be 3 cols by x rows. I have been doing...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
11
by: hasadh | last post by:
Hi, is the assemly code for if..else and switch statements similar. I would like to know if switch also uses value comparison for each case internally or does it jump to the case directly at...
14
by: tbird2340 | last post by:
I want to write an if / then statement and have tried using this: var MyVarMailto; if (Request.Form("LoanRequest") == "Under $250,000") { if (Request.Form("Organization") == "1") { MyVarMailto...
12
by: SA SA | last post by:
I know it is me but i can not get this condition to work. Regardless of Check or credit card it always defaults to else portion of the script. I can't get if (login.PMT_INDICATOR.value == "C") to...
7
by: reon | last post by:
In the below code.. else statements didnt work correctly... the program is to add the positive and negative numbers... if we enter alphabets it will show the wrong entry ,, but thats not...
2
by: pradeep.thekkottil | last post by:
I'm setting up an auction website using PHP and MySQL. There in the section where logged in members can put up new auction in a form, I want to run a form validation where I used if else statements...
5
by: kavithadevan | last post by:
Hi, Here is the script which i am working in this script i am trying to search some events for that i developed this .Its working but if there is no events means i want to display there is no...
2
by: epsilon | last post by:
All: I'm running into trouble figuring this one out. It seems that my decision routine is not working as intended. Does anyone know why my output continues to utilize the "else" portion of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.