Asp – If Statement Not Working as Expected in ASP Classic

asp-classic

I have an if..else statement that will display whether or not the student is qualified to go for competition based from the value in database. But, my code is not working correctly.

My code is as follows:

<% If (rs_view.Fields.Item("StudentStatus").Value="OK") Then %>
<strong><font color="#3300FF" size="-1" face="Arial, Helvetica, sans-serif">
<%Response.Write("You are QUALIFIED to go for competition")%>
</font></strong>

<% Else %>

<strong><font color="#FF0000" size="-1" face="Arial, Helvetica, sans-serif">
<%Response.Write("You are NOT QUALIFIED to go for competition")%>
</font></strong>

<% End If %>

Any ideas?

  • it doesn't work correctly..meaning either the student is qualified or not qualified, it will still display NOT QUALIFIED for both status.

Best Answer

Perhaps the StudentStatus field in your recordset is lowercase? Wrap it in a UCase()?

Also, you can really simplify that code for readability...

<%
Dim RspMsg, RspColor
If (UCase(rs_view("StudentStatus"))="OK") Then 
    RspMsg = "You are QUALIFIED to go for competition"
    RspColor = "#3300FF"
Else
    RspMsg = "You are NOT QUALIFIED to go for competition"
    RspColor = "#FF0000"
End If

%>

<strong><font color="<%=RspColor%>" size="-1" face="Arial, Helvetica, sans-serif">
<%=QualificationResponse%></font></strong>
Related Topic