PDA

View Full Version : Msgbox in vbScript


Anthony1312002
02-09-2005, 03:23 PM
I'm trying using this script to show a popup box when a person selects an ID that is not in the database. The Javascript that you see in the else part of the script works just fine when put in the onload event of the page. The msgbox appears. But for some reason its not working if the recordset is eof. Any thoughts?

If isempty(Request.Form("btnSearch")) Then

sql = "SELECT ReviewID, FUNB_ID, Dept_ID, OrgName, FullNames, ReviewCity FROM tblEmployees "
Set recordset = Server.CreateObject("ADODB.Recordset")
Set recordset = Conn.Execute(sql)

Else

sql = "SELECT ReviewID, FUNB_ID, Dept_ID, OrgName, FullNames, ReviewCity FROM tblEmployees WHERE FUNB_ID = '" & SearchText & "'"
Set recordset = Server.CreateObject("ADODB.Recordset")
Set recordset = Conn.Execute(sql)
if recordset.eof then
recordset.close
Set recordset= Nothing
Response.write("<script type=""text/javascript"">alert(""What is the employee's ID Number? If unavailable enter N/A. Re-select your employee before filling out the rest of the form."");</script>")
Response.Redirect "StaffingReview.asp"
End If
End If

ghell
02-09-2005, 04:42 PM
you cant do MsgBox from serverside i think, you will need to do it clientside in javascript (if possible).. otherwise you will have to display the message in a different way (eg just big red bold text at the top:p)

miranda
02-10-2005, 08:35 AM
You are using a response.Redirect in the same if then statement which basically cancels the javascript alert even though the alert is listed above the redirect.

If this is page is referenced from a form on a different page and that is what you are redirecting to then you have multiple options.
1) You can rewrite it so that the the form and the form handler are on the same page. Basically it will then do a postback to itself so then you can do the alert on eof like you are doing or you can spell out an error on the page in case the user has a non javascript enabled browser.

And if it isnt the same page being redirected to then you have two more options
2) You can add a delayed redirect using javascript or a refresh metatag
3)redirect to the other page and pass a variable along with it. Then on the redirected page use an If/Then statement looking for that variable. Then if it is true the javascript alert is triggered. like so

on Refering page
if recordset.eof then
recordset.close
Set recordset= Nothing
Response.Redirect "StaffingReview.asp?1"
End If

On StaffingReview.asp
dim e
e = Request.Querystring
If e = 1 Then
Response.write("<script type=""text/javascript"">alert(""What is the employee's ID Number? If unavailable enter N/A. Re-select your employee before filling out the rest of the form."");</script>")
End If