Solved

A script block cannot be placed inside another script block

Posted on 2007-11-20
15
1,106 Views
Last Modified: 2008-02-01
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
Comment
Question by:Soluga
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 11

Expert Comment

by:Isisagate
ID: 20319616
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
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20319735
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
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20319748
Wow i see, you are try to use variable of javascript hrpageid in ASP code.
This cannot be done like this.
0
 
LVL 1

Author Comment

by:Soluga
ID: 20319791
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
 
LVL 1

Author Comment

by:Soluga
ID: 20319840
It is trying to process the script when the page loads instead of when I click the hyperlink
0
 
LVL 3

Expert Comment

by:john_steed
ID: 20319875
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
 
LVL 1

Author Comment

by:Soluga
ID: 20319912
what a pain
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Author Comment

by:Soluga
ID: 20319960
Is it possible to execute a javascript function and a vbscript function from one hyperlink?
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20320003
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
 
LVL 1

Author Comment

by:Soluga
ID: 20320030
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
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20320072
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
 
LVL 1

Author Comment

by:Soluga
ID: 20320165
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
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 300 total points
ID: 20320218
Oh, so very simple man, write the same data entry step in your Popup file at the top before anything is submitted.
0
 
LVL 3

Assisted Solution

by:john_steed
john_steed earned 200 total points
ID: 20320284
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
 
LVL 1

Author Comment

by:Soluga
ID: 20320729
See, sometimes the short cuts just dont work out.

Thanks again.
0

Featured Post

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

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now