Solved

Problem with javascript and cgi

Posted on 2000-02-27
1
212 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
ID: 2563821
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
EXCHANGE 2007, SCRIPTS 67 75
Studying Angular for employability 5 80
How can I modify this Excel worksheet with a script? 15 75
Recursively Delete Files 5 68
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…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to count occurrences of each item in an array.

920 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

12 Experts available now in Live!

Get 1:1 Help Now