[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1117
  • Last Modified:

A script block cannot be placed inside another script block

Hi I am trying to run the code below but I keep getting
"A script block cannot be placed inside another script block"

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function trackPageView(target, hrid, url, hrpageid)
{
    if (target != null)
    {

<%
dim oCmd
       SET oCmd_Track = server.createobject("ADODB.Command")
      SET oCmd_Track.ActiveConnection = oConn
      oCmd_Track.CommandText = "dbo.usp_hrTrackPage"
      oCmd_Track.CommandType = adCmdStoredProc
      oCmd_Track.Parameters.Append oCmd_Track.CreateParameter("pageid", adInteger, adParamInput, , + hrpageid)
      oCmd_Track.Parameters.Append oCmd_Track.CreateParameter("intCandidateID", adInteger, adParamInput, , request.cookies("id"))
      oCmd_Track.Execute
       Set oCmd_Track = nothing

%>
 
    openNew(target, hrid, url);
    }
}
//-->
</SCRIPT>

0
Soluga
Asked:
Soluga
  • 7
  • 5
  • 2
  • +1
2 Solutions
 
IsisagateCommented:
try outputing this code outside of the script tags...

<%
dim oCmd
       SET oCmd_Track = server.createobject("ADODB.Command")
      SET oCmd_Track.ActiveConnection = oConn
      oCmd_Track.CommandText = "dbo.usp_hrTrackPage"
      oCmd_Track.CommandType = adCmdStoredProc
      oCmd_Track.Parameters.Append oCmd_Track.CreateParameter("pageid", adInteger, adParamInput, , + hrpageid)
      oCmd_Track.Parameters.Append oCmd_Track.CreateParameter("intCandidateID", adInteger, adParamInput, , request.cookies("id"))
      oCmd_Track.Execute
       Set oCmd_Track = nothing

%>


my assumption is it is generating a script block. What does the view source of the outputted page look like?
0
 
Ashish PatelCommented:
Try this way
<%
dim oCmd 
       SET oCmd_Track = server.createobject("ADODB.Command")
      SET oCmd_Track.ActiveConnection = oConn
      oCmd_Track.CommandText = "dbo.usp_hrTrackPage"
      oCmd_Track.CommandType = adCmdStoredProc
      oCmd_Track.Parameters.Append oCmd_Track.CreateParameter("pageid", adInteger, adParamInput, , + hrpageid)
      oCmd_Track.Parameters.Append oCmd_Track.CreateParameter("intCandidateID", adInteger, adParamInput, , request.cookies("id"))
      oCmd_Track.Execute
       Set oCmd_Track = nothing
%>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function trackPageView(target, hrid, url, hrpageid)
{
    if (target != null)
    {
              openNew(target, hrid, url);
    }
}
//-->
</SCRIPT> 

Open in new window

0
 
Ashish PatelCommented:
Wow i see, you are try to use variable of javascript hrpageid in ASP code.
This cannot be done like this.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
SolugaAuthor Commented:
I have moved the javascript function into the <HEAD> tag (it wasnt previously)
Here is the code for the hyperlink click event....
                    response.write "<td width=200><a href=""javascript: trackPageView('HrPageDetails_one', '" &  request.querystring("HRID") & "', '" &  oRS_GetPageDetails("hrpageURL") & "', '" &  oRS_GetPageDetails("hrpageid") & "')""  class='smallLink'>" & oRS_GetPageDetails("hrpageURL") & "</a></td>"

I know the value are being passed because I can see them in the task bar.

It is now trying to process the asp but it cannot find the variables I have passed to it, here is the error output...

<head>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function trackPageView(target, hrid, url, hrpageid)
{
    if (target != null)
    {

 <font face="Arial" size=2>
<p>Microsoft OLE DB Provider for SQL Server</font> <font face="Arial" size=2>error '80040e10'</font>
<p>
<font face="Arial" size=2>Procedure 'usp_hrTrackPage' expects parameter '@pageID', which was not supplied.</font>
<p>
<font face="Arial" size=2>/shiredevelopmentv2.2/M20_HRDetails/M20_clientviewHrRecord.asp</font><font face="Arial" size=2>, line 131</font>
0
 
SolugaAuthor Commented:
It is trying to process the script when the page loads instead of when I click the hyperlink
0
 
john_steedCommented:
Hey Soluga,

The parameters are passed to the javascript function properly, but they aren't passed on to the VB part. Simply because you can't.
What you could do is get the parameters straight from the querystring inside the VB part (the same way you add them to the hyperlink.

You should also move the VB part out of the javascript function, if i'm not mistaking this way it gets called every time the page is being built, not when you call your function.

Hope this helps
0
 
SolugaAuthor Commented:
what a pain
0
 
SolugaAuthor Commented:
Is it possible to execute a javascript function and a vbscript function from one hyperlink?
0
 
Ashish PatelCommented:
YES, but the script what you have writting is not javascript. Its ASP code, so convert that into VB script and then you can call it.
0
 
SolugaAuthor Commented:
Sorry, yes thats what I meant, can I create a function for the asp code then call both functions from one hyperlink i.e one for the javascript and one for the asp?

How would I tag it onto the end of my hyperlink?

 response.write "<td width=200><a href=""javascript: trackPageView('HrPageDetails_one', '" &  request.querystring("HRID") & "', '" &  oRS_GetPageDetails("hrpageURL") & "', '" &  oRS_GetPageDetails("hrpageid") & "')""  class='smallLink'>" & oRS_GetPageDetails("hrpageURL") & "</a></td>"

0
 
Ashish PatelCommented:
Listen, the only possible solution is onClick of you hyperlink post your form or data to the same page by writtting document.forms[0].submit(); and on submit keep some hidden field so that on the top of the page you can simply work this out first by ASP Code calling and then by the javascript. If you still dont get this, get the source of your page here, and i can get you a bit working.
0
 
SolugaAuthor Commented:
Cant do that, because the hyperlink opens a popup, what I am trying to do is pass the variables to the popup which works fine, ie which uploaded file to load etc, but I want to write a data entry prior to that page loading, so that I can keep track of how many times the user has viewed that particular page. Looks like I am going to have to create a pop up specifically for this function which I wanted to do.

Thanks for all your help.
0
 
Ashish PatelCommented:
Oh, so very simple man, write the same data entry step in your Popup file at the top before anything is submitted.
0
 
john_steedCommented:
asvforce is right, that would be the way to go
or write your page logging code in an include file so you can easily add it to multiple pages
0
 
SolugaAuthor Commented:
See, sometimes the short cuts just dont work out.

Thanks again.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

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