PDA

View Full Version : Alert Boxes...



LittleMan
05-11-2002, 10:56 AM
Right now I have this function:

If Len(Request("UserName")) > 0 AND Len(Request("Password")) > 0 Then

If isNumber(Request("UserName")) Then

filt = "UserName=" & CLng(Request("UserName"))
rsFilter rsClients, filt

If rsClients.EOF OR rsClients.BOF Then
Access = false
mesg = "We're Sorry but your User Name can not be found<br>Please Try again."
Else
If CLng(Request("UserName")) = rsClients("UserName") AND Request("Password") = rsClients("Password") Then
Access = true
.....and then a bunch more...

Later on I've got something like

If Access = False Then
Response.Write mesg
End If

I'd like to have this appear as an alert box though...so something like:

If Access = False Then
MsgBox = mesg
End If

This doesn't work though...how can I change it so that it works?

-Ryan.

no_mac_jack
05-11-2002, 11:49 AM
:D: I tried to do that a long time ago and then I realized what was happening. Doh!

Check out this explanation (http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=121).

:crazy:

~no_mac_jack

LittleMan
05-11-2002, 01:32 PM
I don't really want a 'pop-up' though...I'd like one of those boxes that looks like an error message. Is there a way to write a javascript function with an 'alert' based on the value of the Access variable from the VBScript function?

-Ryan.

no_mac_jack
05-11-2002, 01:48 PM
I don't really want a 'pop-up' though...I'd like one of those boxes that looks like an error message.

That's what it's talking about. It also gives an example of how to do it with javascript. If you want to pass data to it, I would probably just temporarily store the message in a session variable and then redirect to the page that you want the error to show on.


..blablabla...
Session("errMsg") = "Whatever message you have constructed"
Response.Redirect "displayerror.asp"

Then on the page that displays the alert (put this somewhere between the head tags)...


<%
If Session("errMsg") <> "" Then
Response.Write "<SCRIPT LANGUAGE=""JavaScript"" TYPE=""text/JavaScript"">" & vbCrLf
Response.Write "<!-- begin hiding" & vbCrLf
Response.Write "document.onLoad = alert('" & Session("errMsg") & "');" & vbCrLf
Response.Write "// end hiding -->" & vbCrLf
Response.Write "</SCRIPT>" & vbCrLf
Session("errMsg") = Nothing
End If
%>

That will write out the javascript to create an alert with the specified error message once the page has loaded. Be sure that when you are 'putting together' your error message in ASP that you put a back-slash before special characters such as single quotes. If you don't you'll get JavaScript errors.

~no_mac_jack

bud
05-11-2002, 01:57 PM
Ryan


http://216.127.196.144/learn%20it/fpdb/login1.asp



<SCRIPT LANGUAGE=JavaScript>
<!--
function myAlert(txt){
alert(txt);
}
-->
</SCRIPT>

<html>


<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<% If Len(mesg) <> 0 Then %>
<body onload="myAlert('<%=mesg%>')">
<%Else%>
<body>
<%End If%>

bud
05-11-2002, 02:03 PM
Oh I should add that Session objects are needed but try not to over use them... They can suck up resources...

LittleMan
05-11-2002, 02:54 PM
O.k. ... I'm going with your function here Bud...I'm running into a problem with the single quatations though (like you warned me about above NMJ) ...this is what I'm trying but I'm getting an error message:

mesg = "We/'re sorry. Our records indicate that you are not yet a registered user with The President/'s Group."

How can I fix this so that it runs?

bud
05-11-2002, 03:04 PM
Try this

<SCRIPT LANGUAGE=JavaScript>
<!--
var CompanyName = "Thank You The President's Group."

function myAlert(txt){
var eTxt = txt + CompanyName;
alert(eTxt);
}
-->
</SCRIPT>


Then change "we're" too "we are"
////////////////////////////////////////////////////
mesg = "We are Sorry but your User Name can not be found Please Try again. "
////////////////////////////////////////////////////

LittleMan
05-11-2002, 03:06 PM
Bud: it works if I change the direction of the slash to:

mesg = "We\'re sorry. Our records indicate that you are not yet a registered user with The President\'s Group."

You can try it at www.presidentsgroup.com/asp/members.asp

One thing though...when the message box comes up it seems to reload the entire page and you lose the username/password values ... is there a way to keep them in there?

bud
05-11-2002, 03:15 PM
Ryan...

Did you change something?

When loggin in, I use the wrong password, I'm told I'm not a member. But if I enter a good password it lets me in.

Check this section



Else
Access = false
mesg = "Login Failed "
If CLng(Request("UserName")) <> rsClients("UserName") Then
mesg = mesg & "Please Confirm your User Name"
End If
If Request("Password") <> rsClients("Password") Then
mesg = mesg & "Please Confirm your Password"
End If
End If


The page needs to refresh to check the member against the DB... Like NMJ mentioned about the client and server...



you lose the username/password values ...


The Login form did retain my wrong answers.

LittleMan
05-11-2002, 03:20 PM
Yeah, I got rid of that 'if then' clause about username/password and just put in generic: 'you aren't in the db' if either UserName or Password aren't found....

bud
05-11-2002, 03:23 PM
That might confuse some people... Make them try to submit another application for membership... A well written App then will deny them because they already are...

You need to see if the User Name is correct and just tell them that they entered the wrong password...

You could then offer to send them their password if they forgot it...

Try www.dimansystems.com/forgotpass.asp and put your email in there.

LittleMan
05-11-2002, 03:24 PM
Bud try this as the SIN # on your page (it messes up on mine too):

5122006234

you can use any password....

I'm getting this error message on yours:

Error Type:
Microsoft VBScript runtime (0x800A0006)
Overflow: 'CLng'
/learn it/fpdb/login1.asp, line 57

p.s. I'll add the 'if then' statement back in....
p.s.s I'll play around with an emailing script...I'll let you know how it goes either way...

bud
05-11-2002, 04:11 PM
Ok I found it....

Change the Field types in Access for UserName from
"Long Intiger" too "Double"

You will need to remove the Relationship that is set between
the "UserName" fields in Clients and Policies. Then make the field
type change, and reset the Relationship too "Enforse Referential
Integrity"

Add this function into the top set ...



<SCRIPT LANGUAGE=JavaScript RUNAT=Server>
function rsFilter(RS, Where){
if(Where == null) {
Where = "";
}
RS.Filter = Where;
}

function isNumber(numVal){

if(isNaN(numVal))
return false;
else return true;
}

//////// This one ////////////////////////////////////
function GetNumber(numVal){

var tNum = new Number(numVal);
return tNum;


}

</SCRIPT>


Change the following to something like this




If Len(Request("UserName")) > 0 AND Len(Request("Password")) > 0 Then

If isNumber(Request("UserName")) Then
Dim uname
uname = GetNumber(Request("UserName"))
filt = "UserName=" & uname
rsFilter rsClients, filt

If rsClients.EOF OR rsClients.BOF Then
Access = false
mesg = "We\'re Sorry but your User Name can not be found Please Try again.\nThank You The President\'s Group."
Else
If Request("UserName") = CStr(rsClients("UserName")) AND Request("Password") = rsClients("Password") Then
Access = true
If Request.Form("rCheck") = "ON" Then
Response.Cookies("MyMember")("sPass") = "checked"
Response.Cookies("MyMember")("User") = rsClients("Password")
Response.Cookies("MyMember")("Name") = rsClients("UserName")
Response.Cookies("MyMember")("FName") = rsClients("FirstName")
Response.Cookies("MyMember").Expires = "July 4, 2010"
Else
Response.Cookies("MyMember")("sPass") = ""
Response.Cookies("MyMember")("User") = ""
Response.Cookies("MyMember")("Name") = ""
Response.Cookies("MyMember")("FName") = ""
End If
Else
Access = false
mesg = "Login Failed "
If Request("UserName") <> CStr(rsClients("UserName")) Then
mesg = mesg & "Please Confirm your User Name\nThank You The President\'s Group."
End If
If Request("Password") <> rsClients("Password") Then
mesg = mesg & "Please Confirm your Password\nThank You The President\'s Group."
End If
End If
End If

rsClients.Close
Set rsClients = Nothing

Else ' User Name is NOT a number
mesg = mesg & "Please Confirm that you are using your SIN as your User Name\nThank You The President\'s Group."

Access = false
End If ' is a Number

If Access Then
Response.Redirect(loginSuccess)
End If
End If

LittleMan
05-11-2002, 04:40 PM
Ok Bud...I'll try that in a sec...I'm trying to copy your 'send email' function now...

This is the basic code that I've got right now just to test it out. It's not working though...can you see anything really wrong with it?

<%
Dim rsClients, strUserName, strPwd, strEmail

strUserName = CLng(Request.Form("UserName"))

'''''''''''''''''''''''''''''''''''''''''''''' Get a connection to the DB

set di_conn = Server.CreateObject("ADODB.Connection")
di_conn.ConnectionTimeout = 30
di_conn.CommandTimeout = 15

di_conn.Open "DSN=clients;"


'''''''''''''''''''''''''''''''''''''''''''''''''' '' Open Clients table

set di_cmd_client = Server.CreateObject("ADODB.Command")
di_cmd_client.CommandText = "SELECT * FROM Clients WHERE UserName="&strUserName""
di_cmd_client.CommandType = 1
set di_cmd_client.ActiveConnection = di_conn
set rsClients = Server.CreateObject("ADODB.Recordset")
set rsClients.Source = di_cmd_client

rsClients.CursorLocation = 3 ' adUseClient
rsClients.CursorType = 2 ' adOpenStatic
rsClients.LockType = 3 ' set this to adLockOptimistic so we can write to the DB

rsClients.Open

'''''''''''''''''''''''''''''''''''''''''''''''''' ''' Get password and email values

rsClients("Password") = strPwd
rsClients("Email") = strEmail

rsClients.Close
Set rsClients = Nothing

Response.Write strPwd
Response.Write strEmail
%>

bud
05-11-2002, 05:21 PM
Ryan

You're searching the DB for a number so we don't need the semi quotes. (We would if UserName were text)

di_cmd_client.CommandText = "SELECT * FROM Clients WHERE UserName=" & strUserName


Then we need to assign the email and password from the db too... the variables

''' Get password and email values

strPwd = rsClients("Password")
strEmail = rsClients("Email")

Also note my previous post... The SIN will cause a over run if you use it on a number larger than 296000000 (or about) it will break MAX_LONG

That's why you need to convert the form field with the java function...

Or use CDbl instead of CLng

strUserName = CDbl(Request("UserName"))

LittleMan
05-11-2002, 06:05 PM
That did it...I'll play around with the code and add your above functions. Thanks again Bud.

I'll let you know how it goes.

-Ryan.

LittleMan
05-11-2002, 06:28 PM
This is what I've got:

set di_cmd_client = Server.CreateObject("ADODB.Command")
di_cmd_client.CommandText = "SELECT * FROM Clients WHERE UserName=" & strUserName
di_cmd_client.CommandType = 1
set di_cmd_client.ActiveConnection = di_conn
set rsClients = Server.CreateObject("ADODB.Recordset")
set rsClients.Source = di_cmd_client

rsClients.CursorLocation = 3 ' adUseClient
rsClients.CursorType = 2 ' adOpenStatic
rsClients.LockType = 3 ' set this to adLockOptimistic so we can write to the DB

rsClients.Open

'''''''''''''''''''''''''''''''''''''''''''''''''' ''' Get password and email values

If CLng(rsClients("UserName")) > 0 Then
strPwd = rsClients("Password")
strEmail = rsClients("Email")
strTitle = rsClients("MrMrs")
strLastName = rsClients("LastName")
End If

rsClients.Close
Set rsClients = Nothing

If works when the UserName exists in the db otherwise I get an error ...I tried to get around that with the 'CLng if then' statement but I think that I need something else ?!?

bud
05-11-2002, 10:37 PM
Ryan

( Did you change the Data type of the UserName Feild from Long Integer to Double in Access ???? )

you have this

If CLng(rsClients("UserName")) > 0 Then
strPwd = rsClients("Password")
strEmail = rsClients("Email")
strTitle = rsClients("MrMrs")
strLastName = rsClients("LastName")


You can test for a record like this

If rsClients.EOF OR rsClients.BOF Then
mesg = "ERROR: Record Not Found"
Response.Redirect "login.asp"
Else
strPwd = rsClients("Password")
strEmail = rsClients("Email")
strTitle = rsClients("MrMrs")
strLastName = rsClients("LastName")
End If

LittleMan
05-12-2002, 09:27 AM
Of course I forgot to change the datatype :(:

It works now though Bud....I'm having a problem with someone entering text in the field though. You can try it at www.presidentsgroup.com/asp/members.asp and then click the forgot password link....

Here's the code that I'm using to check if it's a number:

If Len(Request("UserName")) > 0 Then
If isNumber(Request("UserName")) Then
If rsClients.EOF OR rsClients.BOF Then
strExists = False
Else
strPwd = rsClients("Password")
strEmail = rsClients("Email")
strTitle = rsClients("MrMrs")
strLastName = rsClients("LastName")
strFullName = rsClients("FirstName") & " " & rsClients("LastName")
End If
Else
strExists = False
End If
Else
strExists = False
End If

Try entering text....it's messing up.

bud
05-12-2002, 10:26 AM
The only thing that I can see



'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''
' If you are filtering the DB up here
' it has not been tested to see if it is indeed a number
' this would cause the problem
'
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''


If Len(Request("UserName")) > 0 Then
If isNumber(Request("UserName")) Then

'''''''''''''''''''''''''''''''''''''''''''''''''' '
' You need to Set your DB Filter here
' because -- we know we have a number now
'''''''''''''''''''''''''''''''''''''''''''''''''' '

If rsClients.EOF OR rsClients.BOF Then
strExists = False
Else
strPwd = rsClients("Password")
strEmail = rsClients("Email")
strTitle = rsClients("MrMrs")
strLastName = rsClients("LastName")
strFullName = rsClients("FirstName") & " " & rsClients("LastName")
End If

Else 'The feild contains text
'''''''''''''''''''''''''''''''
' We do NoT have a number
' So we know we must have text
'''''''''''''''''''''''''''''''
strExists = False
End If

Else 'The feild is empty
''''''''''''''''''''''''''''''''
' We don't have a value
' the Feild is Empty
''''''''''''''''''''''''''''''''
strExists = False
End If

LittleMan
05-13-2002, 05:43 AM
Hey Bud,

I'm filtering the db way up at the top with this line:

di_cmd_client.CommandText = "SELECT * FROM Clients WHERE UserName=" & strUserName

So I guess all of those other functions checking if its a number are useless because they come too late ?!?!

Should I just change this line to read "SELECT * FROM Clients" and then later on put in one of your patented filters:

rsFilter = "UserName=" & strUserName
rsClients.Filter = rsFilter

-Ryan.

bud
05-13-2002, 05:35 PM
I think so...

LittleMan
05-13-2002, 05:50 PM
Yep, works like a charm...

Thanks again Bud...now I've just got to figure out this session variable part and we're set :)

-Ryan.