473,378 Members | 1,447 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,378 software developers and data experts.

How to apply same function to all the images

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 1575
Dormilich
8,658 Expert Mod 8TB
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
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 Expert Mod 8TB
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
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 Expert Mod 8TB
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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...

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.