Solved

javascript alert equivalent when runat=server

Posted on 2008-06-09
13
1,175 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now