Solved

A script block cannot be placed inside another script block

Posted on 2007-11-20
15
1,112 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
[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
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Word Press Fixes to Google Speed Test Issues 2 50
Check input text, Number 7 55
Geolocation works...sometimes 2 37
How does GeoJson relates to Leaflet and Mapbox? 4 48
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

734 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