473,695 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Got a JS problem with Arrays

2 New Member
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 1524
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

Why not start the fadeimages array from 0?
Dec 22 '07 #2
STIAdmin
2 New Member
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 Contributor
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 Recognized Expert Moderator MVP
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
3454
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 guestbook scripts out there - but that doesn't help me learn how to programme arrays !!! The following is the code for the PHP (called externally), which does execute...
11
4460
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 accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
5
1627
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 and LABEL as 1 so I can just write array = whatever array = whatever (I declared array like this:
1
7574
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. There seems to be other ways of doing the jobs of the two and less confusing. The books I read don't provide good examples of situations when I would need an array or indexer. I don't really need a definition of them as I already have that. I...
39
19633
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) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
3
4030
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
2319
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) so after that point whenever you use X it gets replaced by (*X)
3
2642
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 array which reads in the sample name that coincides with the mass and the volume. I have tried the getline function and that didnt work. This is my first class in computer programming and im very new to it so if i have made obviouse mistakes i...
4
2502
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
2451
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 33%) than
0
8649
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9137
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8864
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8838
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3025
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.