473,769 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Small corection needed (Cell Rotation with Javascript)

5 New Member
Hie everybody,
Here at this forum I have found something what I was looking for - rotation of cells in html table, here is the link
http://www.thescripts.com/forum/thre...9304-2-10.html
The gue named RobD posted a nice script there. You can easily modify it for the needs of your table, but one problem occured on my way, maybe somebody can help.
For instance if there is <a> tags inside one table cell, the script willl rotate only the first one. Can anyone give me hint of how to force it to rotate each image I am having in my table.

this.pix.push(c ell.getElements ByTagName('IMG' )[0].src); - this string finds src of the first image only. Maybe I need to change some attributes or something else. I am not really a specialist in Javascript.
thsi string, I guess, write elemenst inside the cell - (el = cell.getElement sByTagName('A')[0]).lastChild.nod eValue =
this.txt[idx];
Can anyone tell me what is lastChild.nodeV alue and [0] ??
Thanks in advance
May 21 '06 #1
8 4317
Banfa
9,065 Recognized Expert Moderator Expert
getElementsByTa gName returns a collection (or an array) of items the [0] is then referencing the 1st item in that collection, you can access the 2nd item with [1] the 3rd with [2] and so on. You can find the number of items with the length method

[php]
var collection = cell.getElement sByTagName('A') ;

for( var ix=0; ix < collection.leng th; ix++ )
{
alert( "Link " + ix + " = " + collection[ix].value );
}
[/php]

lastChild refers to the last child element of the current element (a child being an element contain by the current element).
May 22 '06 #2
RomanRusso
5 New Member
Had couple of very busy days in university, there is small break before Psychology test on Thursday.
If you have any chance of answering it would be great.
I will eleborate on what I need to do for this university project.
So I have a html table with cell randomly placed inside of it, every time the page is loaded :D
My cell looks like this
[HTML]<td>
<div>
<img src ="/1.PNG"
width ="200" height ="200" border="0"
usemap ="#1" />
<map id ="1"
name="1">
<area shape ="rect" coords ="0,0,100,10 0"
href ="/info1" target ="_blank"
alt="info 1" />
<area shape ="rect" coords ="100,100,200,2 00"
href ="/info2" target ="_blank"
alt="info 2" />
</map>
</div>
</td>
[/HTML](I would like to link half of image to first page another to second page)

I think I asked a bit wrong question at first, sorry, but what I really need is to rotate href for both areas, as well as other attributes of 2nd area tag. Thanks for giving me a hint but would you specify (I am not programmer, so it is difficult for me) where to put the code you gave me? and you wrote that it is a php code!
Here the script I am using (found on this forum by the way)
<script>
Expand|Select|Wrap|Line Numbers
  1. //<![CDATA[
  2.  
  3. /**********************************************/
  4. var table_ids = [ 'maintable' ];
  5. /**********************************************/
  6.  
  7. var alldivs = document.getElementsByTagName('DIV');
  8.  
  9.  
  10.  
  11.  
  12. function Rotator(table_id)
  13. {
  14. this.table = document.getElementById(table_id);
  15. this.cells = this.table.getElementsByTagName('TD');
  16. this.ncells = this.cells.length;
  17. this.pix = [];
  18. this.hrefs = [];
  19. this.id = [];
  20. this.n = [];
  21. this.shapehref = [];
  22. this.coordshref = [];
  23. this.idx_array = new Array(this.ncells);
  24.  
  25. function read()
  26. {
  27. var cell, n = 0;
  28. while (cell = this.cells.item(n++))
  29. {
  30. this.pix.push(cell.getElementsByTagName('IMG')[0].src);
  31. this.hrefs.push(cell.getElementsByTagName('AREA')[0].href);
  32. this.id.push(cell.getElementsByTagName('AREA')[0].alt);
  33. this.n.push(cell.getElementsByTagName('IMG')[0].alt);
  34. this.shapehref.push(cell.getElementsByTagName('AREA')[0].shape);
  35. this.coordshref.push(cell.getElementsByTagName('AREA')[0].coords);
  36. } this.shuffle();
  37. }
  38. this.read = read;
  39.  
  40. function shuffle()
  41. {
  42. var idx, i, ind1, ind2, temp;
  43. for (i = 0; i < this.ncells; ++i)
  44. this.idx_array[i] = i;
  45. for (i = 0; i < this.ncells; ++i)
  46. {
  47. ind1 = Math.floor(Math.random() * this.ncells);
  48. ind2 = Math.floor(Math.random() * this.ncells);
  49. temp = this.idx_array[ind1];
  50. this.idx_array[ind1] = this.idx_array[ind2];
  51. this.idx_array[ind2] = temp;
  52. } this.write();
  53. }
  54. this.shuffle = shuffle;
  55.  
  56. function write()
  57. {
  58. var cell, el, idx, n = 0;
  59. while (cell = this.cells.item(n))
  60. {
  61. idx = this.idx_array[n++];
  62. cell.getElementsByTagName('IMG')[0].src = this.pix[idx];
  63. (el = cell.getElementsByTagName('AREA')[0]).href =
  64. this.hrefs[idx];
  65. (el = cell.getElementsByTagName('AREA')[0]).alt =
  66. this.id[idx];
  67. (el = cell.getElementsByTagName('IMG')[0]).alt =
  68. this.n[idx];
  69. (el = cell.getElementsByTagName('AREA')[0]).shape =
  70. this.shapehref[idx];
  71. (el = cell.getElementsByTagName('AREA')[0]).coords =
  72. this.coordshref[idx];
  73. } alldivs.item(0).style.visibility = 'visible';
  74. }
  75. this.write = write;
  76.  
  77. this.read();
  78. }
  79.  
  80. onload = function()
  81. {
  82. if (document.getElementById && document.createElement)
  83. for (var i = 0; i < table_ids.length; ++i)
  84. new Rotator(table_ids[i]);
  85.  

If you know the answer, please help. It would be great if I could do this with your help :)
May 23 '06 #3
Banfa
9,065 Recognized Expert Moderator Expert
I will get to this but I just a bit tired right now. It would be helpful if you could post a link to the actual page that needs work or if it is not only yet attach it to a post (you will need to go advanced and rename the file to a text file to do this).
May 23 '06 #4
RomanRusso
5 New Member
Here I am attaching a text file with some comments inside, I hope everything what is there is pretty clear. English is my second language by the way.
Thanks again for helping, I spent so much time trying to solve this problem...
I really cannot show the page because I had it maybe a week ago (my friend kindly gave me password and I could test it, so I can assure you the script is working), but right now all I can test it on university server only, but I do not think somebody can access it form outside.
Attached Files
File Type: txt code.txt (7.4 KB, 908 views)
May 24 '06 #5
Banfa
9,065 Recognized Expert Moderator Expert
Sorry must of missed the post, unfortunately once again it is midnight here but I will try to look at it tomorrow.
May 30 '06 #6
Banfa
9,065 Recognized Expert Moderator Expert
A-ha, right I can see the problem and I have the answer.

The problem is that when the images are display randomly the 1st link (top left) moves with the image but the second link (bottom right) stays in it's original table cell instead of moving with the image.

The answer is that you are only altering the data for the first link (which I think you knew) and what I have already said does apply, because you are only accessing the first elements in the collections.

In this line (by the way none of what I have posted is php I just use the php tages because it colours the code and makes it easier to follow, it is all Javascript)

[php]
this.hrefs.push (cell.getElemen tsByTagName('AR EA')[0].href);
[/php]

the function call cell.getElement sByTagName('ARE A') returns a collection, as I said. A collection is an array of objects so cell.getElement sByTagName('ARE A')[0] references the first array element or the first AREA tag in the cell. However there are 2 AREA tags in the cell and you wish to swop the href values of both of them so you will need to access the second array element as well cell.getElement sByTagName('ARE A')[1].

To fix the script everywhere you use the this.hrefs0 object you need to double up to handle not just the first href but the second href to so this

[php]
this.hrefs0 = [];

...

this.hrefs0.pus h(cell.getEleme ntsByTagName('A REA')[0].href);

...

(el = cell.getElement sByTagName('ARE A')[0]).href = this.hrefs0[idx];
[/php]

becomes this

[php]
this.hrefs0 = [];
this.hrefs1 = [];

...

this.hrefs0.pus h(cell.getEleme ntsByTagName('A REA')[0].href);
this.hrefs1.pus h(cell.getEleme ntsByTagName('A REA')[1].href);

...

(el = cell.getElement sByTagName('ARE A')[0]).href = this.hrefs0[idx];
(el = cell.getElement sByTagName('ARE A')[1]).href = this.hrefs1[idx];
[/php]

Note, I have left out vast tracts of code to highlight the changes

Also I think this

[php](el = cell.getElement sByTagName('ARE A')[0]).href = this.hrefs0[idx];[/php]

will work just as well if it is written like

[php]cell.getElement sByTagName('ARE A')[0].href = this.hrefs0[idx];[/php]



Lastly at the moment you are swopping the href values of the AREAs, however if you need to have different MAPs associated with each image (i.e. not as it currently stands all MAPs are geometrically the same) then it might be easier to swop the usemap value of each image rather than altering the AREA values directly.
May 31 '06 #7
Banfa
9,065 Recognized Expert Moderator Expert
P.S. here is my altered version of the code you posted
Attached Files
File Type: txt code.txt (7.7 KB, 813 views)
May 31 '06 #8
RomanRusso
5 New Member
Something weird happens, I was trying to do what you proposed here myself even before you posted the reply, but for some strange reason it cannot do this. Simple can't see another area tag. CHanging [0] to [1] is not working(((((
But as you proposed I was experimenting with usemap, but it cant see it as well. Would you be so kind to make it clear of how to swap usemap since the way I am doing is no good?
Just give me a hint about usemap
Thanks again

P.S. the thing is that when I suplemented my code with all these three line hrefs1 with [1], it stops rotating((((
Jun 8 '06 #9

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

Similar topics

2
2036
by: Xenophobe | last post by:
I'm having a brain freeze on how to go about creating the logic for evenly distributing a group of items in rotation through multiple iterations. I'm particularly looking for logic flow help and not necessarily syntax examples. Let's say we have a database table with the following pieces of fruit: apple apple banana
21
3838
by: M. Clift | last post by:
Hi All, Could someone help me out with this? items = ('a', 'b', 'c', 'd') items + 1 = ( 'b', 'c', 'd', 'a') items + 2 = ( 'c', 'd', 'a', 'b') items + 3 = ( 'd', 'a', 'b', 'c') trans = 1
1
4290
by: Rick | last post by:
I have a script of rolling images. I would like it so that each time an image changes in cell1 some text in cell2 changes. How can this be done. <html> <head> <title>TITLE</title>
3
4766
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
13
1352
by: Giggle Girl | last post by:
My pages need to unfold gracefully even if Javascript is disabled, but I can't get this to work? Please help, Javascript Gurus!! <noscript> document.write('<span class=warning><b>Warning</b>: You must enable javascript for this page to work properly!</span>') </noscript>
2
8058
by: Peter | last post by:
Hi, this is the code, and new row and new cell generated ok, but why the onclick and onmouseover doen't work? Thank you in advance! <html> <head> <script language="javascript"> function inserttable() {
5
3504
by: Russell Warren | last post by:
Does anyone have an easier/faster/better way of popping from the middle of a deque than this? class mydeque(deque): def popmiddle(self, pos): self.rotate(-pos) ret = self.popleft() self.rotate(pos) return ret
2
2112
by: the other john | last post by:
I am looking for ideas on how to create a rollover that triggers an image rotation in another location. I know how to create a function for basic rollovers, image swapping sort of thing, but I know know how to create the rotation. This is what the client wants... ....create a circle of images, each of which will trigger an image rotation in the center of this circle until the mouseout. Yea, I'm a little green with js.
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
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...
0
10039
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
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
9860
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...
1
7406
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...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3955
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
3
2814
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.