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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Alert in ASP?

Status
Not open for further replies.

Maldini

Technical User
Nov 10, 2002
55
0
0
GB
Hi,

I've some ASP code that processes data with the database. As I'm catching any errors that are found, I'm hoping to use JavaScript to show the error caused to the user.

Does anyone have a tutorial on how I can pass a string in ASP to javascript or how to run some javascript from ASP?

PS. I've tried a number of ways, such as writing a javascript function and referring to its name, passing the string in as variable; or using response.write and writing some javascript within my ASP VB code, but neither show the alert window.

Thanks in advance.
Maldini.
 
this should do what you want. Of course if you want you can substitute the Request.QueryString variable for whatever you want to use - Form variables, Session variables etc...
Code:
<%
If Request.QueryString("error") <> "" Then
  Response.Write "<script language=""javascript"" type=""text/javascript"">" & vbcrlf & _
                 "alert('" & Request.QueryString("error") & "');" & vbcrlf & _
                 "</script>" & vbcrlf
End If
%>

Tony
_______________________________________________________________
 
Here are a few JavaScript alerts I've done:

Response.Write "<script type='text/javascript'>alert('" & string & "');</script>"

Response.Write "<script type='text/javascript'>alert('No records matched the criteria.\n\nYou may continue with the new record or else close the page.');</script>"

Response.Write "<script type='text/javascript'>alert('Yet to be developed.');</script>"

J. Paul Schmidt, Freelance ASP Web Developer
Classic ASP Design Tips, ASP Web Database Sample (Freely Downloadable)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top