Solved

javascript alert equivalent when runat=server

Posted on 2008-06-09
13
1,183 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
Technology Partners: 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem in javascript 17 58
hide and show spans from dropdown selection 3 38
Javascript question 8 44
Add Promise to Existing Code 6 31
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

738 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