• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1196
  • Last Modified:

javascript alert equivalent when runat=server

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
chris_desborough
Asked:
chris_desborough
  • 7
  • 4
  • 2
1 Solution
 
Pratima PharandeCommented:
Try Response.write()  instade of alert
0
 
chris_desboroughAuthor Commented:
Yes, tried that and it works fine but would prefer an alert box if possible.
0
 
Pratima PharandeCommented:
I tried your code ..

is working for me even if runat server = true
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Michel PlungjanIT ExpertCommented:
response.write("<script>alert('record found');</script>");
0
 
chris_desboroughAuthor Commented:
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
 
chris_desboroughAuthor Commented:
To pratima mcs comment,  I get the following error:

Microsoft JScript runtime error '800a138f'
Object expected
/testjavascript.asp, line 27
0
 
chris_desboroughAuthor Commented:
Hi guys,

Does this link provide a possible solution?  http://codingforums.com/archive/index.php?t-64488.html
0
 
Michel PlungjanIT ExpertCommented:
response.write("<scr"+"ipt>alert('record found');</scr"+"ipt>");
0
 
chris_desboroughAuthor Commented:
No sorry, still doesn't work:

Microsoft JScript runtime error '800a1391'

'response' is undefined

/testjavascript.asp, line 31
0
 
Michel PlungjanIT ExpertCommented:
Response ?? Case sensitive?
0
 
chris_desboroughAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
I am sorry. I have no idea. Does it not give you a line number?
0
 
chris_desboroughAuthor Commented:
Yes, debug said the error was in onclick="sendBack('9755')"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 7
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now