Solved

Problem with javascript and cgi

Posted on 2000-02-27
1
224 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
[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
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

630 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