Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javascript alert equivalent when runat=server

Posted on 2008-06-09
13
Medium Priority
?
1,185 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
[X]
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
  • 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

715 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