Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

javascript alert equivalent when runat=server

Posted on 2008-06-09
13
1,181 Views
Last Modified: 2012-05-05
Hi,

Have an ASP page that runs some Javascript. It fails on 'alert("record found")' because I've specified runat="server" I take it.

Is there an alternative method to display an alert with Javascript??

THanks
<%@LANGUAGE="JAVASCRIPT"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
<SCRIPT LANGUAGE="JavaScript" runat="server">
 
	adOpenForwardOnly = 3;
    adLockReadOnly = 3;
    adCmdText = 1;
	
	var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:\\inetpub\\esvc000711\\database\\docstores.mdb"; 
    
    var ConnectObj = Server.CreateObject("ADODB.Connection");
    var RS = Server.CreateObject("ADODB.Recordset");
    var sql="SELECT Username, ContactName FROM Users WHERE Username='10024';";
 
    ConnectObj.Open (myConnect);
    RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);
 
    var recCount = RS.RecordCount;
    Response.Write ("SQL = "+sql+" ,Field Count = "+recCount);
	
	if (recCount > 0) 
    {
      foundIt = 1;
      alert("record found")
    }
    else
    {
      foundIt = 0;
    }
	
    RS.Close();
    myConnect.Close();
 
</SCRIPT>
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<body>
</body>
</html>

Open in new window

0
Comment
Question by:chris_desborough
  • 7
  • 4
  • 2
13 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 21748695
Try Response.write()  instade of alert
0
 
LVL 1

Author Comment

by:chris_desborough
ID: 21748709
Yes, tried that and it works fine but would prefer an alert box if possible.
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 21748802
I tried your code ..

is working for me even if runat server = true
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21749639
response.write("<script>alert('record found');</script>");
0
 
LVL 1

Author Comment

by:chris_desborough
ID: 21754511
No sorry, fails with below msg:

Active Server Pages error 'ASP 0138'
Nested Script Block
/testjavascript.asp, line 27
A script block cannot be placed inside another script block.
0
 
LVL 1

Author Comment

by:chris_desborough
ID: 21754611
To pratima mcs comment,  I get the following error:

Microsoft JScript runtime error '800a138f'
Object expected
/testjavascript.asp, line 27
0
 
LVL 1

Author Comment

by:chris_desborough
ID: 21755788
Hi guys,

Does this link provide a possible solution?  http://codingforums.com/archive/index.php?t-64488.html
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21757985
response.write("<scr"+"ipt>alert('record found');</scr"+"ipt>");
0
 
LVL 1

Author Comment

by:chris_desborough
ID: 21773159
No sorry, still doesn't work:

Microsoft JScript runtime error '800a1391'

'response' is undefined

/testjavascript.asp, line 31
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21777013
Response ?? Case sensitive?
0
 
LVL 1

Author Comment

by:chris_desborough
ID: 21789656
Yes that's what it was. Now working in my test page. I've incorporate the changes into the live page but unfortunately the table cell that initiates the Javascript fails.  'sendBack' function now fails with Object expected. Is anything ever easy???

<td style="cursor: hand" onclick="sendBack('9755')"><span class="style5">B3751</span></td>

<script language="Javascript" runat=server>
<!--
 
function sendBack(clinic)
{

    adOpenForwardOnly = 3;
    adLockReadOnly = 3;
    adCmdText = 1;
      
      var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:\\inetpub\\esvc000711\\database\\docstores.mdb";
      
    var ConnectObj = new ActiveXObject("ADODB.Connection");
    var RS = new ActiveXObject("ADODB.Recordset");
    var sql="SELECT Username, ContactName FROM Users WHERE Username="+clinic+";";

    ConnectObj.Open (myConnect);
    RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);

    var recCount = RS.RecordCount;
    Response.Write ("SQL = "+sql+" ,Record Count = "+recCount);
      
      if (recCount > 0)
{
foundIt = 1;
Response.Write("<scr"+"ipt>alert('record found');</scr"+"ipt>");
}
else
{
foundIt = 0;
}
   RS.Close();
}
//-->
</script>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21791214
I am sorry. I have no idea. Does it not give you a line number?
0
 
LVL 1

Accepted Solution

by:
chris_desborough earned 0 total points
ID: 21797061
Yes, debug said the error was in onclick="sendBack('9755')"
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question