A
A
Alexander2011-08-11 15:38:36
ActionScript
Alexander, 2011-08-11 15:38:36

What is the error in the script (JS)?

Good afternoon!
Question to those who know JavaScript
there is a script, I did not write

var img_id = new Array(1,1,2,3);<br/>
<br/>
var img_color = new Array(<br/>
'Brilliant 1',<br/>
'Brilliant 1',<br/>
'Brilliant 2',<br/>
'Brilliant 3'<br/>
);<br/>
<br/>
var img_url = new Array(<br/>
'color/1.jpg',<br/>
'color/1.jpg',<br/>
'color/2.jpg',<br/>
'color/3.jpg'<br/>
);<br/>
<br/>
var img_arr = new Array();<br/>
function preloadImages()<br/>
{<br/>
 for (var id in img_url) {<br/>
 img_arr[id] = new Image;<br/>
 img_arr[id].src = img_url[id];<br/>
 }<br/>
}<br/>
<br/>
preloadImages(); <br/>
<br/>
function setMainImage(id)<br/>
 { <br/>
 if(id &lt;= 50)<br/>
 {<br/>
 big = document.getElementById('main_image');<br/>
 document.getElementById('login_response').innerHTML = img_color[id];<br/>
 }<br/>
 else<br/>
 {<br/>
 big = document.getElementById('main_image_ef');<br/>
 document.getElementById('login_response_ef').innerHTML = img_color[id];<br/>
 }<br/>
 <br/>
 bg = document.getElementById('i' + id);<br/>
 if (big && bg)<br/>
 {<br/>
 var id_img = 0;<br/>
 for (var index in img_id) {<br/>
 if (img_id[index] == id) {<br/>
 id_img = index;<br/>
 }<br/>
 }<br/>
 big.src = img_arr[id_img].src;<br/>
 }<br/>
 return false;<br/>
 }

so the server, when loading a page with this script, writes the following errors to the logs
File does not exist: /domain/www/function () { for (var i = 0; i <= this.length; i++) { this.shift( ); }}
[Thu Aug 11 16:19:10 2011]
[error] [client **.***.**.*] File does not exist: /domain/www/function () { var newArray = []; for (var i = 0; i < this.length; i++) { newArray.insert(this[i]); } return newArray;}
what's the problem? and how can this be fixed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shiberz, 2011-08-11
@zlobin

This is all from the fact that js is written by a person who has not even read the initial level of documentation.
for (var id in img_url) - this construction iterates not only the elements of the array, but also all other properties of the object. Change to
for (var i=0; i<img_url.length; i++) {
var id = img_url[i];
....
}

A
Anatoly, 2011-08-11
@taliban

/domain/www/function ()…
Do these logs go during preload, or when displaying the main image?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question