CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Can I execute a JavaScript function defined in main in a Perl subroutine?

 



craigtussey
New User

Nov 20, 2018, 2:39 PM

Post #1 of 3 (441 views)
Can I execute a JavaScript function defined in main in a Perl subroutine? Can't Post

I have a subroutine in a Perl module I include (use) in main. I have been executing this same code in the main body without problem. I decided to take it out of the body and make it a subroutine because the same code is used in several Perl parts of the application configuration I'm working with.

The subroutine tries to executes a JavaScript function brought in in a SCRIPT section in the HEAD of main. Can the subroutine execute the JavaScript function? The error file tells me the subroutine is not known.

As I said, I have been executing the same code inline for some time without problem. All I did was wrap the code in a sub container with namespace definitions.


Code
sub shoAnalysis { # Show analysis - shoAnalysis('container3',$ltappbgcolr,$darkbluetext,$alnm,$inactivetabs,@alines);  

my ($cntr, $ltappbgcolr, $darkbluetext, $alnm, $inactivetabs, @alines) = @_; # Input colors and message.

my ($tab, $tabcontent); # Scalar.

my ($i); # Numeric.

print"<DIV ID='$cntr' STYLE='DISPLAY:block;BACKGROUND-COLOR:#$ltappbgcolr;TEXT-ALIGN:left;'>

<P STYLE='COLOR:#$darkbluetext;'>Analysis <A CLASS='zzz tn' Title='Clear The Analysis' HREF='javascript:resetTabs($alnm,\"#$inactivetabs\");'><IMG SRC='../images/clrxxx.jpg' STYLE='VERTICAL-ALIGN:middle;'></A></P>

<UL ID='tabmenu'>\n";

for ($i=0; $i < $alnm; $i++) {
($tab,$tabcontent) = split('!',$alines[$i]);
$tabcontent =~ tr/^/ /; # Spaces were preserved this way.
$tabcontent =~ s/http\*/http~/g;
print "<LI ONCLICK='activeTab2($alnm,$i,\"$tabcontent\")' ONMOUSEOVER=\"setStatus(' ');\" ONMOUSEOUT=\"setStatus(' ');\"><A ID='tab$i'>$tab</A></li>\n";
}

print"</UL>

<DIV ID='content'></DIV>

</DIV>\n";

}


The activeTab2 function is the JavaScript code.

Any help will be appreciated.
ct


BillKSmith
Veteran

Nov 22, 2018, 7:42 AM

Post #2 of 3 (414 views)
Re: [craigtussey] Can I execute a JavaScript function defined in main in a Perl subroutine? [In reply to] Can't Post

Your question does not make it clear whether it is the Java subroutine or the perl subroutine that is not known. I will assume that it is the Java.

The perl subroutine that you show creates some html and sends it to your client. The client cannot tell whether that html came from a perl subroutine, a perl main program, or even from a file. This suggests that your change should work, but you have not implemented it correctly.

You have not said anything about how you load the perl subroutine. I assume that all your inline code is in the same file and that you added the subroutine to that file.

To debug the problem, I suggest that you return to the inline version that 'works'. Add the perl subroutine (exactly as you posted it), but do not make any other changes. Verify that it still works with this subroutine loaded but not used. Now replace one instance of your inline code with the subroutine call and test it. If that works, replace one more instance. Continue replacing them one at a time until you find the first one that causes a problem.

Post the working version of the offending section and the failing version of the same section. Do not be surprised if we have more questions at this point.
Good Luck,
Bill


craigtussey
New User

Nov 22, 2018, 11:19 AM

Post #3 of 3 (410 views)
Re: [BillKSmith] Can I execute a JavaScript function defined in main in a Perl subroutine? [In reply to] Can't Post

Bill,

Thanks for responding. The code I posted is now working and being implemented. Perl subroutines (and this one is brought in in my Perl module at the top of main), I believe, have Perl and JavaScript resources in their scope and available to them.

I think the problem I was having was the Perl module I was pulling in was down level. Sometimes in all the browsers I test in, down level Perl and Javascript includes will 'stick around'. I scrub browser history, memory, the cache, and my hard drive to be safe and this has always resolve that issue.

Again, thanks for your response.
ct

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives