Solved

VBScript Message Box

Posted on 2014-01-22
15
1,233 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 33

Expert Comment

by:Big Monty
ID: 39800951
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
ID: 39800982
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 33

Expert Comment

by:Big Monty
ID: 39801012
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:slegy
ID: 39801075
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 33

Expert Comment

by:Big Monty
ID: 39801121
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
ID: 39801177
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 33

Expert Comment

by:Big Monty
ID: 39801195
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
 

Author Comment

by:slegy
ID: 39801209
He is redirected to a name lookup page.
0
 
LVL 33

Expert Comment

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

Author Comment

by:slegy
ID: 39801243
Working on it now.
0
 

Author Comment

by:slegy
ID: 39801572
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 33

Accepted Solution

by:
Big Monty earned 175 total points
ID: 39801702
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
ID: 39801917
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
ID: 39813843
You guys are terrific. This is my primary focus tomorrow.
0
 

Author Closing Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA & VBSCRIPT: re-adapt log file 13 33
Code Manager | Snippits 2 36
A Table within a User Form 24 42
batch file or script 4 24
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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