473,394 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Got a JS problem with Arrays

Happy Holidays to all of you!

This is my first time posting. I'm working on a web project and trying to get this done before Christmas. The limitation is that I'm using an out of the box program and I don't have the skills to change it quickly, and it only outputs in a structured way... so I am not able to go dig into the code of the out-of-box program and solve it.

This it the first time I've really dug into JS. My JS knowledge is very limited and I could write very simple JS, that is about it. I have a form that I'm building that outputs data in between < script > .... </ script >. The data output begins at number 1 of the array. It is shown below

Expand|Select|Wrap|Line Numbers
  1. <!-- BEGIN OUTPUT FROM MY SITE ***
  2. <script type="text/javascript">
  3. var fadeimages=new Array()
  4. fadeimages[1]=["../Portals/3/PropertiesImages/thm_host_20071209_035346.jpg", "http://www.google.com", ""] 
  5. fadeimages[2]=["../Portals/3/PropertiesImages/thm_host_20071209_091810.jpg", "http://www.google.com", ""] 
  6. fadeimages[3]=["../Portals/3/PropertiesImages/thm_host_20071209_094217.jpg", "http://www.google.com", ""] 
  7. fadeimages[4]=["../Portals/3/PropertiesImages/thm_host_20071209_094947.jpg", "http://www.google.com", ""] 
  8. fadeimages[5]=["../Portals/3/PropertiesImages/thm_host_20071209_095901.jpg", "http://www.google.com", ""] 
  9. fadeimages[6]=["../Portals/3/PropertiesImages/thm_host_20071209_100204.jpg", "http://www.google.com", ""] 
  10. fadeimages[7]=["../Portals/3/PropertiesImages/thm_host_20071209_111622.jpg", "http://www.google.com", ""] 
  11. var fadebgcolor="white"
  12. </script>
  13.  
  14. <script type="text/javascript">
  15. //new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
  16. new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R") 
  17. </script>
  18. *** END OUTPUT FROM MY SITE-->
  19.  
I copied the JS from this site: http://www.dynamicdrive.com/dynamici...nslideshow.htm

I tried changing this piece of the code:
Expand|Select|Wrap|Line Numbers
  1. for (p=1;p<theimages.length;p++){
  2. this.postimages[p]=new Image()
  3. this.postimages[p].src=theimages[p][0]
  4. }
  5.  
Where p=0, but did not work when I changed to p=1.

Here is the full original source (sorry its long...)

Expand|Select|Wrap|Line Numbers
  1. ////NO need to edit beyond here/////////////
  2.  
  3. var fadearray=new Array() //array to cache fadeshow instances
  4. var fadeclear=new Array() //array to cache corresponding clearinterval pointers
  5.  
  6. var dom=(document.getElementById) //modern dom browsers
  7. var iebrowser=document.all
  8.  
  9. function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
  10. this.pausecheck=pause
  11. this.mouseovercheck=0
  12. this.delay=delay
  13. this.degree=10 //initial opacity degree (10%)
  14. this.curimageindex=0
  15. this.nextimageindex=1
  16. fadearray[fadearray.length]=this
  17. this.slideshowid=fadearray.length-1
  18. this.canvasbase="canvas"+this.slideshowid
  19. this.curcanvas=this.canvasbase+"_0"
  20. if (typeof displayorder!="undefined")
  21. theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
  22. this.theimages=theimages
  23. this.imageborder=parseInt(borderwidth)
  24. this.postimages=new Array() //preload images
  25. for (p=0;p<theimages.length;p++){
  26. this.postimages[p]=new Image()
  27. this.postimages[p].src=theimages[p][0]
  28. }
  29.  
  30. var fadewidth=fadewidth+this.imageborder*2
  31. var fadeheight=fadeheight+this.imageborder*2
  32.  
  33. if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
  34. document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"> <div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0; filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1; background-color:'+fadebgcolor+'"></div> <div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0; filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1; background-color:'+fadebgcolor+'"></div></div>')
  35. else
  36. document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
  37.  
  38. if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
  39. this.startit()
  40. else{
  41. this.curimageindex++
  42. setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
  43. }
  44. }
  45.  
  46. function fadepic(obj){
  47. if (obj.degree<100){
  48. obj.degree+=10
  49. if (obj.tempobj.filters&&obj.tempobj.filters[0]){
  50. if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
  51. obj.tempobj.filters[0].opacity=obj.degree
  52. else //else if IE5.5-
  53. obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
  54. }
  55. else if (obj.tempobj.style.MozOpacity)
  56. obj.tempobj.style.MozOpacity=obj.degree/101
  57. else if (obj.tempobj.style.KhtmlOpacity)
  58. obj.tempobj.style.KhtmlOpacity=obj.degree/100
  59. else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
  60. obj.tempobj.style.opacity=obj.degree/101
  61. }
  62. else{
  63. clearInterval(fadeclear[obj.slideshowid])
  64. obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
  65. obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
  66. obj.populateslide(obj.tempobj, obj.nextimageindex)
  67. obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
  68. setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
  69. }
  70. }
  71.  
  72. fadeshow.prototype.populateslide=function(picobj, picindex){
  73. var slideHTML=""
  74. if (this.theimages[picindex][1]!="") //if associated link exists for image
  75. slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
  76. slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
  77. if (this.theimages[picindex][1]!="") //if associated link exists for image
  78. slideHTML+='</a>'
  79. picobj.innerHTML=slideHTML
  80. }
  81.  
  82.  
  83. fadeshow.prototype.rotateimage=function(){
  84. if (this.pausecheck==1) //if pause onMouseover enabled, cache object
  85. var cacheobj=this
  86. if (this.mouseovercheck==1)
  87. setTimeout(function(){cacheobj.rotateimage()}, 100)
  88. else if (iebrowser&&dom||dom){
  89. this.resetit()
  90. var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
  91. crossobj.style.zIndex++
  92. fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
  93. this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
  94. }
  95. else{
  96. var ns4imgobj=document.images['defaultslide'+this.slideshowid]
  97. ns4imgobj.src=this.postimages[this.curimageindex].src
  98. }
  99. this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
  100. }
  101.  
  102. fadeshow.prototype.resetit=function(){
  103. this.degree=10
  104. var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
  105. if (crossobj.filters&&crossobj.filters[0]){
  106. if (typeof crossobj.filters[0].opacity=="number") //if IE6+
  107. crossobj.filters(0).opacity=this.degree
  108. else //else if IE5.5-
  109. crossobj.style.filter="alpha(opacity="+this.degree+")"
  110. }
  111. else if (crossobj.style.MozOpacity)
  112. crossobj.style.MozOpacity=this.degree/101
  113. else if (crossobj.style.KhtmlOpacity)
  114. crossobj.style.KhtmlOpacity=this.degree/100
  115. else if (crossobj.style.opacity&&!crossobj.filters)
  116. crossobj.style.opacity=this.degree/101
  117. }
  118.  
  119.  
  120. fadeshow.prototype.startit=function(){
  121. var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
  122. this.populateslide(crossobj, this.curimageindex)
  123. if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
  124. var cacheobj=this
  125. var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
  126. crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
  127. crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
  128. }
  129. this.rotateimage()
  130. }
  131.  
  132. </script>
  133.  
I hope I'm making sense here.

-Eric
Dec 22 '07 #1
4 1496
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

Why not start the fadeimages array from 0?
Dec 22 '07 #2
I would start the array at [0], but I have a slight problem: I have an out of the box program that outputs the data starting at 1. =(

Its either I wait several weeks to months for the developers of the "out of the box" program by submitting an addition request or... I get this JS code figured out. The latter method is probably the best bet in terms of time.

If you think you can solve it, I'm willing to pay you for your time. Send me your rate and a time estimate as to when you'll be able to get this nailed out. A little pocket change for Christmas! Email me at **** - email removed

-E
Dec 23 '07 #3
mrhoo
428 256MB
If you copied the script from dynamic drive, or anywhere else, you should credit the author. Have you offered him any Christmas cash?
Dec 23 '07 #4
acoder
16,027 Expert Mod 8TB
If you think you can solve it, I'm willing to pay you for your time. Send me your rate and a time estimate as to when you'll be able to get this nailed out. A little pocket change for Christmas! Email me at **** - email removed
That's not the way this site works. Either you get free help or no help - take your pick!

If you've made use of a few free scripts, it may not be a bad idea to follow mrhoo's advice and donate some of the amount (that you were prepared to pay to get this fixed) to the authors, but that is entirely up to you.

If you have a "proper" job, you can post in the Jobs forum.

I've removed your email as it's against the site rules.
Dec 24 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dariusz | last post by:
I want to use arrays in my website (flat file for a guestbook), but despite having read through countless online tutorials on the topic, I just can't get my code to work. I know there are...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
5
by: jeremy targett | last post by:
Hello, in my program I use 2-dimensional arrays to hold two integer values for each of i members of a list. array holds a starting position, and array holds a label - in fact I #defined START as 0...
1
by: mdub317 | last post by:
I'm totally new to programming and I am wondering; when would be a good time to use an array or an indexer? I want to know what types of applications would make good use of arrays or indexers. ...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
3
by: alcabo | last post by:
Hello, I'd like to improve several critical routines involving arrays (vectors and matrices)... How are arrays stored in memory? Row major or column major? (Like in C or like Fortran?)
29
by: Ancient_Hacker | last post by:
It sure would be nice if I could have a macro that add a level of indirection to its argument. So if I write: AddIndirection( X ) The macro AddIndirection will do: #define X (*X) ...
3
by: MariyaGel | last post by:
I have wrote the program and it worked fine until I had to include one more array into it. As you can see below the two arrays of volume and mass are working properly now I need to include a third...
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
19
by: Jim West | last post by:
The execution speed of the following code is dramatically faster if I declare some arrays globally rather than locally. That is FOO a, b, c; void bar() { ... } runs much faster (up to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.