Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBScript Message Box

Posted on 2014-01-22
15
Medium Priority
?
1,457 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 34

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 34

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 34

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 34

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 34

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 34

Accepted Solution

by:
Big Monty earned 700 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 54

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 300 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Integration Management Part 2
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

971 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