ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old September 24th, 2003, 11:20 PM
aspuser25 aspuser25 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 141 aspuser25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
alert or messagebox

I am not clear ... whether to use alert of javascript or messagebox of VBScript in ASP. But what i want is that when a user has some error i want to display a pop-up kind of a thing saying "you have not entered all the values" ... and when he click "ok" then he should be directed to the same page where he was enterign the values. I tried this but in my case i am just being redirected to the page ..and my message box in not being popped up!

here is my code:
<%
DIM RSA
DIM QUERY1
DIM RSA2
DIM QUERY2
DIM Conn
dim adCmdText
dim stAge

session("newStdId") = Request.form("stdID")
session("newStdName") = Request.form("stdName")
session("newStdUserName") = Request.form("stdUserName")
session("newStdPassword") = Request.form("stdPassword")
session("newStdAge") = Request.form("stdAge")

StAge = Request.form("stdAge")
adCmdText = 1
'create and open database connection
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "dsn=school"

'create commad object
set objCmd = server.createobject("adodb.command")

If Request.form("newStudent") = "Click to save details of new student" then
If Request.form("stdname") <>"" and Request.form("stdUsername") <> "" and Request.form("stdpassword")<> "" and Request.form("stdAge")<> "" then
Set RSA2 = Server.CreateObject("ADODB.Recordset")
QUERY2 = "SELECT student_name from student_info where student_username='"&Request.form("stdUsername")&"'"
RSA2.open QUERY2, "dsn=school"
if RSA2.EOF then
QUERY1 = "INSERT INTO student_info (student_name,student_username, student_password,student_age) VALUES ('"&Session("newStdName")&"','"&Session("newStdUserName")&"','"&Session("NewStdPassword")&"',"&Request.form("stdAge")&")"
set objCmd.ActiveConnection = Conn
objCmd.CommandText = Query1
objCmd.CommandType = adCmdText
'execute the command
objCmd.Execute
response.write "<font color=#000080 size=6>" & "Student details have been saved!"
else
response.write "<font color=#000080 size=6>" & "A student by the same username exists! Please create another username."
end if
'response.write session("newStdName") "ID is: "
else
%>
<SCRIPT language="vbscript">
msgbox("YOUR HAVE NOT ENTERED ALL THE VALUES")
</SCRIPT>
<%
Response.Redirect("createStudUser.asp")
End If
end if
'close and dereference database objects
set objCmd = nothing
conn.close
set conn = nothing

%>
<html>
<head>

<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body BGCOLOR="pink">
</body>
<html>

Reply With Quote
  #2  
Old September 25th, 2003, 09:40 AM
imbrokn imbrokn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: NJ
Posts: 428 imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 34 m 8 sec
Reputation Power: 10
Send a message via AIM to imbrokn
You can't use a the msgbox() function in ASP. ASP code is run on the server, so really if the message box were to come up it would come up on the server not on the users machine. You could do something with javascript I suppose. However, it may just be easier to use all javascript if you want to validate a form rather than bothering with validating it with ASP then somehow getting to javascript the fact that the form isn't done so you can show your alert.

Reply With Quote
  #3  
Old September 25th, 2003, 11:46 AM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 6 m 22 sec
Reputation Power: 76
Javascript is commonly used for form validation. However, you can use asp if you worry about people having javascript disabled. However, you will not be able to display an alert box, you will just get text on the page, maybe in red to make it stand out. http://www.haneng.com/lessons_13.asp has some info on writing ASP validation scripts

Reply With Quote
  #4  
Old September 25th, 2003, 03:12 PM
R2D2 R2D2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Third chipset next to the master jumper...
Posts: 16 R2D2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You may not be able to use msgbox function directly in your asp code as yes it's running on the server but you could use it in a vbscript function just as you would do with javascript.

Here's an exemple, put this on your server and test it. You could validate a whole form if you want. Am always using the message box function in my asp apps. You have more possibilities than with the javascript "doll" message.

<form name="callingform" method="post" action="msgbox.asp">

enter a value : <input type="text" name="testing">
<INPUT TYPE="submit" name="btnsave" value="Process">
<INPUT TYPE="submit" name="btnCancel" value="Cancel">
</form>

<script language=VBScript>
'ON FORM SUBMIT FUNCTION VALIDATION
Function callingform_OnSubmit
validation = True

If Document.callingform.testing.value = "" Then
msgbox "You must enter a value", vbOkONly + VBCritical, "No empty field"
validation = False
Document.callingform.testing.focus
End If

'Submit the form if validation has passed, else do not submit
If validation = True Then
callingform_OnSubmit = True
Else
callingform_OnSubmit = False
End If
End Function
'END ON FORM SUBMIT FUNCTION VALIDATION
</SCRIPT>

Reply With Quote
  #5  
Old September 25th, 2003, 03:15 PM
R2D2 R2D2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Third chipset next to the master jumper...
Posts: 16 R2D2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Also, you could use all the same msgbox state as you usually use in vb.

Greetings

Reply With Quote
  #6  
Old September 25th, 2003, 04:19 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
i'd go with karsh, vbscript is just not widely enough supported to be using as a validator let alone getting input from the user.

Reply With Quote
  #7  
Old September 25th, 2003, 04:25 PM
R2D2 R2D2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Third chipset next to the master jumper...
Posts: 16 R2D2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
there's pro's and con's on much any techniques poeple are using to code.. I've used vbscript to validate for a long time now and never had problems with it. If it's simply a form validation before submitting I surely will use vbscript. As for javascript I use it when I need more complex thing that in fact vbscript would not be a good solution.

But once again.. if it's simply a basic form validation, vbscript will be much more nicely presentable to the user and easy to manipulate if you're asking a question to the user than with javascript.

My humble opinion.

Reply With Quote
  #8  
Old September 25th, 2003, 04:30 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
Quote:
I've used vbscript to validate for a long time now and never had problems with it. If it's simply a form validation before submitting I surely will use vbscript.


then you don't have a wide end user case. vbscript is not as widely supported as javascript, period

Reply With Quote
  #9  
Old September 25th, 2003, 04:33 PM
R2D2 R2D2 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Third chipset next to the master jumper...
Posts: 16 R2D2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
:-) as you wish...

Greetings

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > alert or messagebox


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway