Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsgBox or Alert Box in ASP ???

Status
Not open for further replies.

ufobaby

MIS
Sep 25, 2001
238
US
hi,
want to validate the form input before i submit the page and show an alert box to the user. the fillowing is the code can any one suggest a way to do it
======== CODE ========
<%
Dim ConLog 'For Opening Connection to Db
Dim rs 'For RecordsSet

'==== Before this i would like to validate and show the
'==== alert box, on error the following code should not execute

Set ConLog = Server.CreateObject(&quot;adodb.connection&quot;)
ConLog.Open &quot;Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\inetpub\Set rs = ConLog.Execute(&quot;select * from usr where username='&quot; & _
session(&quot;me&quot;) & &quot;' and password='&quot; & Request.Form(&quot;txtOldPwd&quot;) & &quot;'&quot;)
if rs.eof = false then
ConLog.Execute(&quot;Update usr set password='&quot; & Request.Form(&quot;txtReNew&quot;) & &quot;' where username='&quot; & Session(&quot;me&quot;) & &quot;'&quot;)
Response.Write &quot;Successfully Changed&quot;
end if
%>
<html>

<head>
<title>Change Password</title>
</head>
<body>
<form method = post id=form1 name=form1>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;50%&quot;>Old Password</td>
<td width=&quot;50%&quot;><input type=&quot;text&quot; name=&quot;txtOldPwd&quot; size=&quot;20&quot;></td>
</tr>
</table>
</form>
</body>
</html>

[cheers]
Niraj [noevil]
 
if you don't want too, even knowing I agree with snowboardr in using javascript for this, you can just write a bit doing your validation where you want it and on a condition not being or being met do something like this

Dim pass, MyMsg
pass = form1.txtoldPwd.value
If pass = &quot;&quot; then
MyMsg = msgbox(&quot;You have entered a incorrect value!&quot;)
exit sub
end if










[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
onpnt, I attempted to get the msgbox script to work, but it doesnt seem to work. You sure thats correct?
 
hi, thanks but i used the following code, any improvements in this are appreciated. But am still not clear on using the Msgbox function in ASP. it says &quot;Premission denied&quot;. Also i read that this function will popup on the serve and not on the client side. Any info on this.
===== CODE ====
<%
Dim ConLog 'For Opening Connection to Db
Dim rs 'For RecordsSet

'==== Now the code does not execute as the page is not submitted

Set ConLog = Server.CreateObject(&quot;adodb.connection&quot;)
ConLog.Open &quot;Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\inetpub\Set rs = ConLog.Execute(&quot;select * from usr where username='&quot; & _
session(&quot;me&quot;) & &quot;' and password='&quot; & Request.Form(&quot;txtOldPwd&quot;) & &quot;'&quot;)
if rs.eof = false then
ConLog.Execute(&quot;Update usr set password='&quot; & Request.Form(&quot;txtReNew&quot;) & &quot;' where username='&quot; & Session(&quot;me&quot;) & &quot;'&quot;)
Response.Write &quot;Successfully Changed&quot;
end if
%>
<html>

<head>
<title>Change Password</title>
</head>
<body>
<script LANGUAGE=&quot;JavaScript&quot;>
<!--
function confirmSubmit()
{
if (form1.txtOldPwd.value == &quot;&quot;) {
alert(&quot;Stop&quot;)
return false;
}
}
// -->
</script>
<form method = post id=form1 name=form1 onSubmit=&quot;return confirmSubmit()&quot;>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;50%&quot;>Old Password</td>
<td width=&quot;50%&quot;><input type=&quot;text&quot; name=&quot;txtOldPwd&quot; size=&quot;20&quot;></td>
</tr>
</table>
</form>
</body>
</html>
 
I think you should make a better message then just stop.. the user will be confused as to why it says &quot;stop&quot;..
 
hee heeee [upsidedown] this was just a test script... the text will be definetly meaningful.

but what the question now is regarding the msgbox function. any ideas

[cheers]
Niraj [noevil]
 
Sorry forgot to tell you that you can't use the msgbox function from with the <% %>
you'll need to use the vbscript tags but ofcourse unless you have viewers only on IE this is not a good idea.

although if you want to keep this server side without the use of javascript alerts then I usually response.write to the page the error etc..

[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
here's a example of how I like to deal with the fact that the msgbox function does not work server side
on condition not being met
<%
Response.Write(&quot;Error has occured! Please click the back button and try again.&quot;)
response.write(&quot;<br>&quot;)
response.write(&quot;<input type='button'&quot;)
response.write(&quot;value='Back'&quot;)
response.write(&quot;onClick='javascript:history.go(-1)'>&quot;)
%>
this is great when you want to relay a message that may be lengthy. I use this often with database work for relaying explanations on why some errors may have happened and what action to take to fix them.

has saved the help desk a lot of calls within my company and they seem to like the idea.

[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top