|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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> |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
||||
|
||||
|
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
|
|
#4
|
|||
|
|||
|
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> |
|
#5
|
|||
|
|||
|
Also, you could use all the same msgbox state as you usually use in vb.
Greetings |
|
#6
|
|||
|
|||
|
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.
|
|
#7
|
|||
|
|||
|
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. |
|
#8
|
|||
|
|||
|
Quote:
then you don't have a wide end user case. vbscript is not as widely supported as javascript, period |
|
#9
|
|||
|
|||
|
:-) as you wish...
Greetings |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > alert or messagebox |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|