473,469 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to apply same function to all the images

17 New Member
i have to files
1).html file>>>it has one function defined inside it that is changeIt() that works on the page loads.
2).js file >>>it has 1 functions that is changeeIt() and it works at the image click...

Both are working well for single image,but i want to all more image on the same page.. so how to make the use of these function at images

1)the coding of html file is as under>>>.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script language="javascript" src="C:\Documents and Settings\Administrator\Desktop\external.js"></script>
  5. <script langauge="javascript">
  6. function changeIt()
  7. {
  8.  
  9. var width=50;
  10. var height=50;
  11. document.image.width=width
  12. document.image.height=height
  13. }
  14. </script>
  15.  
  16. </head>
  17. <body>
  18. <body onload="changeIt();">
  19. <img src="C:\Documents and Settings\Administrator\Desktop\a.jpg" name="image" onclick="changeeIt();"> 
  20.  
  21. </body>
  22. </html>
2)coding of .js file is as under..

Expand|Select|Wrap|Line Numbers
  1. var count=1;
  2. function changeeIt()
  3. {
  4. if(count==1)
  5. {
  6. var width=500
  7. var height=500
  8. document.image.width=width
  9. document.image.height=height
  10. count=2;
  11. }
  12. else if(count==2)
  13. {
  14. var amrit1=50
  15. var pal=50
  16. document.image.width=amrit1
  17. document.image.height=pal
  18. count=1;
  19. }
  20. }
Please somebody help..

Thanks in advance
Oct 11 '10 #1
5 1580
Dormilich
8,658 Recognized Expert Moderator Expert
add onclick="changeeIt();" to every image that should execute this function.

to make the changeIt() function work on every image, you simply have to specify that fact.

Expand|Select|Wrap|Line Numbers
  1. // set image to 50 x 50
  2. function changeIt()
  3. {
  4. this.width  = 50;
  5. this.height = 50;
  6. }
Expand|Select|Wrap|Line Numbers
  1. // apply for every image
  2. var i, imgs = document.images;
  3. for (i = imgs.length; i--;) {
  4.     changeIt.call(imgs[i]);
  5. }
Oct 11 '10 #2
amritpalpathak
17 New Member
Dormilich, i done as u said as follow ,but it is not working


Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script language="javascript" src="/var/www/external.js"></script>
  5. <script langauge="javascript">
  6. function changeIt()
  7. {
  8.  
  9. this.width=50;
  10. this.height=50;
  11. }
  12.  
  13.  
  14. var i, imgs = document.images;
  15.  for (i = imgs.length; i--;)
  16.  {
  17.      changeIt.call(imgs[i]);
  18.  }
  19. </script>
  20. </head>
  21. <body>
  22. <body onload="changeIt();">
  23. <img src="/home/administrator/Desktop/aa.jpeg" name="image" onclick="changeeIt();"> 
  24. <img src="/media/data/fun/fun all/bb" name="image" onclick="changeeIt();">
  25.  
  26. </body>
  27. </html>
Oct 12 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
but it is not working
of course, you call the images (the for() loop) when not even the html body is loaded. you need to call that after you finished loading the document.

PS. it’s not <script langauge="javascript">, it’s <script type="text/javascript">
Oct 12 '10 #4
amritpalpathak
17 New Member
so please tell me where to put this code

Expand|Select|Wrap|Line Numbers
  1.  var i, imgs = document.images;
  2.   for (i = imgs.length; i--;)
  3.   {
  4.       changeIt.call(imgs[i]);
  5.   }

i am new to javascript so dont no more about it .

Thanks for all reply upto now
Oct 12 '10 #5
Dormilich
8,658 Recognized Expert Moderator Expert
put it in a function and call that onload.
Oct 12 '10 #6

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

Similar topics

2
by: Susanna | last post by:
Hi all, I'm using the following slideshow script that I found on the web to display changing images with a crossfade effect. Eventually I will be adding many more images to the slideshow. The...
2
by: Whitney | last post by:
I ran across a chunk of code that allows me to blend images in and out (works great!) but now I need to figure out a way to randomize the order that these images appear. I have a bunch of pics and...
1
by: Christopher Benson-Manica | last post by:
IE 5.0 apparently does not support the apply() method for function objects - the following fails: function foo() { alert( this.length ); } foo.apply( ); Is there a convenient way to add an...
1
by: Thomas Brunko | last post by:
Hy, I'm working on a hash table and came upon a small problem. For a better explanation I've included an extract of the header file for the hash module: typedef struct TABLE * TABLE_P; typedef...
1
by: Arnaud Diederen | last post by:
Hello everyone, I have a little problem with IE6. Imagine I have a webapp that has a main/root/parent window, in which there is a function (called: executor()) that makes use of the...
7
by: sfeher | last post by:
Hi All, Is there a way to preserve the arguments across functions? I have: <script> function myFirstFunction() { // arguments = 'param1'
3
by: littleark | last post by:
Hi everybody, I have a typical javascript images preloader, it works fine both on Firefox and on IE in my intranet (local server). It works fine on the Internet (remote server) in IE. In...
1
by: psbasha | last post by:
Hi, I have gone thru ActiveState Python help for the apply() function.They say that this method is depricated in 2.3 Version.I would like to know whether this function can be used.If so,when can...
3
by: yawnmoth | last post by:
Based on my understanding of the apply function, the following code snippet should, at the very least, not yield any errors. Unfortunately, it does, suggesting my understanding is... limited. Any...
2
by: TK | last post by:
HI, I need an example for the usage of the apply()-function. Can you help me? Thanks. o-o Thomas
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
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
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,...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.