Solved

Problem with javascript and cgi

Posted on 2000-02-27
1
209 Views
Last Modified: 2013-12-25
When I write my cgi script with the print qq|  |; thing,
I'd get the following error with my javascript :

CGI ERROR
==========================================
Error Message       : Error loading required libraries.
Check that they exist, permissions are set correctly and that they compile.
Reason: syntax error at ./html.pl line 627, near "))
      "
Can't use subscript on constant item at ./html.pl line 630, near "++]"
Can't use subscript on constant item at ./html.pl line 631, near "++]"
Can't use subscript on constant item at ./html.pl line 631, near "1]"
Can't use subscript on constant item at ./html.pl line 631, near "j]"
Can't use subscript on constant item at ./html.pl line 632, near "2]"
syntax error at ./html.pl line 634, near "//used "
Unmatched right bracket at ./html.pl line 635, at end of line

The script is a rollover script provided by dreamweaver. Its :

function MM_swapImage() { //v2.0
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
   if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  }
 }
  document.MM_swapImgData = swapArray; //used for restore
}

The line with swapArray was made the error...


what is wrong with the script?
Hope someone would shed some light into this.
0
Comment
Question by:Aphroditus
1 Comment
 

Accepted Solution

by:
akf earned 100 total points
Comment Utility
Okay, you have a perl script that uses "print qq|[stuff]|" to emit your Javascript. Simple fix: you have | in your Javascript, so you can't use | as a delimiter with qq. Looking at your javascript, it would be safe to quote with qq#:

print qq#function MM_swapImage() { //v2.0
 var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
[. . .]
 document.MM_swapImgData = swapArray; //used for restore
                   } #;

A more readable way to accomplish the same thing:

print <<"ENDJS"';
function MM_swapImage() { //v2.0
 var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
[. . .]
 document.MM_swapImgData = swapArray; //used for restore
                   }
ENDJS



0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
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)
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 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

6 Experts available now in Live!

Get 1:1 Help Now