VBscript ASP Help If Then

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
rcandela
Posts: 6
Last visit: Thu Sep 13, 2012 4:10 am

VBscript ASP Help If Then

Post by rcandela »

I'm trying to make this button appear only if a value in SQL = 'Deactive'

For some reason, the way my If Then is set up, doesn't make the button () appear when the statement is in fact true.

Code: Select all

<% IF ((rsUsersMod.Fields.Item("STATUS") = "Deactive")) Then%> 
    <form action="" method="POST" name="reactivateuser" > 
        <input name="deleteButton" type="image" src="images/reactivate.png" value="Reactivate" onclick="return confirm('Are you sure you want to reactivate this user?');"> 
        <input type="hidden" name="delete" value="reactivate"> 
        <input type="hidden" name="recordId" value="<%= rsUsersMod.Fields.Item("UNIQUE_ID").Value %>"> 
    </form>
<%End If%> 
User avatar
rcandela
Posts: 6
Last visit: Thu Sep 13, 2012 4:10 am

VBscript ASP Help If Then

Post by rcandela »

All that does is actually display the Field Value on the page, but it doesn't make the form appear afterwards:

Code: Select all

<% 
value=rsUsersMod.Fields("STATUS").Value 
Response.Write(value) 
IF value = "Deactive" Then 
 %> 
    <form action="" method="POST" name="reactivateuser" > 
        <input name="deleteButton" type="image" src="images/reactivate.png" value="Reactivate" onclick="return confirm('Are you sure you want to reactivate this user?');"> 
        <input type="hidden" name="delete" value="reactivate"> 
        <input type="hidden" name="recordId" value="<%= rsUsersMod.Fields.Item("UNIQUE_ID").Value %>"> 
    </form>
<%End If%>
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBscript ASP Help If Then

Post by jvierra »

I am surptised that I can still write proficiently in ASP> It ha been a long time. AASP.NET is so much easier.

Here is a complete and working example:

Code: Select all

<%@ language="VBSCRIPT" %>
<%
 Dim rs
 Set conn = Server.CreateObject("ADODB.Connection")
 conn.ConnectionString="Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=WebTestDB;Data Source=.sqlexpress;"
 conn.Open
 Set rs = conn.Execute("select * from dbo.Names")
%>
<html>
<head>
<meta name="GENERATOR" content="SAPIEN Technologies PrimalScript 2012">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Document Title</title>
</head>
<body>
<table>
<%While Not rs.EOF%>
    <%If LCase(Trim(rs.Fields("FirstName").Value)) <> "joe" Then%>
 <tr>
  <td><%=rs.Fields("ID").Value%></td>
  <td><%=rs.Fields("FirstName").Value%></td>
  <td><%=rs.Fields("LastName").Value%></td>
 </tr>
 <%End If%>
<%rs.MoveNext%>
<%Wend%>
 
</table>
</body>
</html>

I have no idea what is in your database. Y have to attend to teh fact that matches against data require very special handling for many reasons.

A database can have unicode characters. It can have spaces after or before the field contents. In most cases it is important to force the case and trim the strings. If the database character set is wrong then you may not be able to use ASP.

I cannot see your database and I cannot gues as to what you are doing. You must addess these issues on your own. I have shown you the mechanism for assuring the logic will work. I have no idea if you are typing it in correctly or if the values in your database are correct.
This topic is 11 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked