Solved

javascript alert equivalent when runat=server

Posted on 2008-06-09
13
1,182 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Title # Comments Views Activity
maven not picking latest jar instead picking old jar from .m2 12 42
Tools for analysis of code 4 44
Review of the nodejs code 1 35
Rotate images for Web Page 11 24
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

679 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