Solved

VBScript Message Box

Posted on 2014-01-22
15
1,289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 53

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add 'N to prepared ASP/VB insert statement 1 37
Macro to open folder and copy data from all excel files 10 75
Split on ASP 8 52
Add Rows on a Table 8 53
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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