Solved

VBScript Message Box

Posted on 2014-01-22
15
1,177 Views
Last Modified: 2014-01-31
I don't have a clear understanding of how to display information to the user in VBScript. We're running an ASP site and I'm doing some validation in VBScript. I would like to display a message box with "yes" "no" options. I've read that this is not possible when running server side. I've tried to do it in JavaScript, but I get no output.

 sql = "SELECT COUNT(*) FROM Members WHERE (Members.last = '" & last_name & "' AND Members.first = '" & first_name & "' AND Members.password = '" & email & "');"
		   Set rs=conn.Execute(sql)
		 
		   If CInt(rs.Fields(0)) > 0 Then%>	

			  <SCRIPT LANGUAGE=JavaScript>
              alert("You have entered an invalid or unrenewed member ID.");
              window.location='../../index3.asp';
              </script>
            <%
		   else. . .	

Open in new window

0
Comment
Question by:slegy
  • 8
  • 6
15 Comments
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
that is correct, you will need to use client side code (javascript) to display a message to the user. I would set a flag on the server side if there was an error, and check that flag on the body onload event:

dim isError : isError = false

sql = "SELECT COUNT(*) FROM Members WHERE (Members.last = '" & last_name & "' AND Members.first = '" & first_name & "' AND Members.password = '" & email & "');"
		   Set rs=conn.Execute(sql)
		 
		   If CInt(rs.Fields(0)) > 0 Then
                          isError = true
		   else
                         '-- continue processing your server side code
                   end if
<html>
<head>

<SCRIPT LANGUAGE=JavaScript>
        function showError() {
              alert("You have entered an invalid or unrenewed member ID.");
              window.location='../../index3.asp';
        }
</script>
</head>
<body <%if isError then%> onload="showError();" <%end if %> >
other html content
</body>
</html>

Open in new window

0
 

Author Comment

by:slegy
Comment Utility
The entire page is VBScript. The example I included above has worked for me before, but on this particular page, I cannot produce any output.
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
well, if you don't want to implement my solution, I'll offer one more up:

the best way to check for whether records have been returned is to change

If CInt(rs.Fields(0)) > 0 Then

to

if rs.BOF and rs.EOF then
0
 

Author Comment

by:slegy
Comment Utility
I'm sorry. I'm afraid I haven't been clear. I want to display a message if "CInt(rs.Fields(0)) > 0". Based on your previous suggestion, I was just pointing out that there are no html, head or body tags. It is a full page of VBScript, and in the validation process I would like to be able to display information to the member.
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
ok I see what you're doing. It seems like you're doing some kind check against the database and if the data isn't there, then let the end user know (maybe it's a login page?).

The best way to handle this, since there's no other html on the page, if the validation fails, redirect the user back to the either where they came from (with a querystring paramter indicating there was an error that you could check against on the body onload statement) or an error page saying whatever message you want to display (I would do the first option).

The reason it's not working now is because since there's no other html on the page, the script block you're writing out to the screen is invalid markup, you would need to include the rest of the html tags to make it valid. Thus the reason to redirect to another page, it's a lot simpler to do.
0
 

Author Comment

by:slegy
Comment Utility
Here's my predicament. We're implementing social media login. The code on this page is  receiving the results of the social media login and comparing it against our database. In the particular example I posted, the user has specified "renew" but according to the db, he has already renewed and is a current member. There really is no place to send him. The user wanted me to display a message asking if the intent is to renew someone else. So you are saying that if I add the html tags, I could make it work.
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
in short yes...

The user wanted me to display a message asking if the intent is to renew someone else.

how do you plan on handling the user input from this question?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:slegy
Comment Utility
He is redirected to a name lookup page.
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
then as long as you have a valid html page, then that script block should work fine.
0
 

Author Comment

by:slegy
Comment Utility
Working on it now.
0
 

Author Comment

by:slegy
Comment Utility
Well, I worked on this all afternoon with no success. I'm sure that I've made something similar to my initial example work before, but nothing is working now. I'm going to include some of my code as I adjusted it to your example. Possibly you can see where I'm off base. Problem too is that I need to be able to generate 2 or 3 of these messages in the course of the processing.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
	Dim connection_token, site_subdomain, site_public_key, site_private_key, memID, return_code, social_provider, member_token, memName, first_name, last_name, email, cnt, sql, logType, errMsg, whichdir, whichname, filesys, whichFN, message
	Dim conn, rs
	Dim isMember : isMember = false
	Dim http: Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
	
	  'Get connection_token
	  connection_token = request("connection_token")
.
.
.
		  
			   sql = "SELECT COUNT(*) FROM ilcaMembers WHERE (ilcaMembers.last = '" & last_name & "' AND ilcaMembers.first = '" & first_name & "' AND ilcaMembers.password = '" & email & "');"
			   Set rs=conn.Execute(sql)
			 
			   If CInt(rs.Fields(0)) > 0 Then
				 isMember = true
.
.
.
%>
<head>		
 <SCRIPT LANGUAGE=JavaScript>
 function showError() 
 {
	alert("You have entered an invalid or unrenewed member ID.");
	window.location='../../index3.asp';
 }
 </script>
</head>

<body <%if isMember then%> onload="showError();" <%end if %> >

</body>
</html>

Open in new window

0
 
LVL 32

Accepted Solution

by:
Big Monty earned 175 total points
Comment Utility
you're missing the closing "end if" tag. try this:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
	Dim connection_token, site_subdomain, site_public_key, site_private_key, memID, return_code, social_provider, member_token, memName, first_name, last_name, email, cnt, sql, logType, errMsg, whichdir, whichname, filesys, whichFN, message
	Dim conn, rs
	Dim isMember : isMember = false
	Dim http: Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
	
	  'Get connection_token
	  connection_token = request("connection_token")
.
.
.
		  
			   sql = "SELECT COUNT(*) FROM ilcaMembers WHERE (ilcaMembers.last = '" & last_name & "' AND ilcaMembers.first = '" & first_name & "' AND ilcaMembers.password = '" & email & "');"
			   Set rs=conn.Execute(sql)
			 
			   If CInt(rs.Fields(0)) > 0 Then
				 isMember = true
                           end if
.
.
.
%>
<head>		
 <SCRIPT LANGUAGE=JavaScript>
 function showError() 
 {
	alert("You have entered an invalid or unrenewed member ID.");
	window.location='../../index3.asp';
 }
 </script>
</head>

<body <%if isMember then%> onload="showError();" <%end if %> >

</body>
</html>

Open in new window


what you're saying is in your code is that if there are records returned, the error message will pop up. if you have to have different messages, you may want to try this approach:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
	Dim connection_token, site_subdomain, site_public_key, site_private_key, memID, return_code, social_provider, member_token, memName, first_name, last_name, email, cnt, sql, logType, errMsg, whichdir, whichname, filesys, whichFN, message
	Dim conn, rs
	Dim isMember : isMember = false
	Dim http: Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
	dim msg: msg = ""

	  'Get connection_token
	  connection_token = request("connection_token")
.
.
.
		  
			   sql = "SELECT COUNT(*) FROM ilcaMembers WHERE (ilcaMembers.last = '" & last_name & "' AND ilcaMembers.first = '" & first_name & "' AND ilcaMembers.password = '" & email & "');"
			   Set rs=conn.Execute(sql)
			 
			   If CInt(rs.Fields(0)) > 0 Then
				 isMember = true
                                 msg = "You have entered an invalid or unrenewed member ID."
                           end if

         if validateCase2 then
                 isMember = true
                 msg = "second validation message."
         end if

         if validateCase3 then
                 ismember = true
                 msg = "third validation message."
         end if
.
.
.
%>
<head>		
 <SCRIPT LANGUAGE=JavaScript>
 function showError() 
 {
	alert("<%=msg%>");
	window.location='../../index3.asp';
 }
 </script>
</head>

<body <%if isMember then%> onload="showError();" <%end if %> >

</body>
</html>

Open in new window

0
 
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 75 total points
Comment Utility
If you want a more modern look, I like using modals.  It gives a nice flow.  I use bootstrap in my projects but if you are using jquery  / jquery ui  http://jqueryui.com/dialog/#modal-message

The basic code is http://jqueryui.com/dialog/#default
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#dialog" ).dialog();
  });
  </script>
</head>
<body>
 
<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
 
 
</body>
</html>

Open in new window

The way you would handle is in asp is to call the js function as a response.write.
In the below code, the modal is actually a div that sits hidden on your page.  When you call the js by response.write.  You can fill the modal with static html or via your vb script or even ajax.   That would allow one modal for many multiple messages.    
[code]<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
<% 
theJS=""
theJS=theJS&"<script>"
theJS=theJS&"  $(function() {"
theJS=theJS&"    $( '#dialog' ).dialog();"
theJS=theJS&"  });"
theJS=theJS&"   </script>"


if something="wrong" then
    response.write theJS
end if
%>
</head>
<body>
 
<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
 
 
</body>
</html>

Open in new window

0
 

Author Comment

by:slegy
Comment Utility
You guys are terrific. This is my primary focus tomorrow.
0
 

Author Closing Comment

by:slegy
Comment Utility
Again, thank you so much. I see I have a lot of learning and catching up to do.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now