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

How to Call .js file(functions) at onclick image

This is the html file
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <body onload="changeIt();">
  4. <head>
  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. </head>
  16. <img src="/home/administrator/Desktop/aa.jpeg" name="image" onclick=src="/var/www/external.js/changeeIt();"> 
  17. </body>
  18. </html>
And this is the .js file

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


onclick event is not working .....
Oct 9 '10 #1
4 15432
Dormilich
8,658 Expert Mod 8TB
your onclick definition is wrong.

the syntax is onclick="function_name();", period. you cannot pass anything else (like where the function is defined, that doesn’t make sense to the JavaScript parser)
Oct 10 '10 #2
onclick="function_name();

this is for that if the function is defined at the same page... but here i have a .js file which have 2 functions and i want to use those function at image click...

Thanks
Oct 10 '10 #3
dgourd
25
What you have to do is include the javascript file, preferably between the <head></head> tags. Then you would set the onclick to the function. For example,
Expand|Select|Wrap|Line Numbers
  1. <head>
  2.     <script language="javascript" src="path/to/external.js"></script>
  3. </head>
  4. <body>
  5.     <img src="path/to/image.gif" onclick="function_name()" />
  6. </body>
Oct 10 '10 #4
Dormilich
8,658 Expert Mod 8TB
this is for that if the function is defined at the same page
incorrect, JavaScript looks for the function in all available sources, including external files.
Oct 10 '10 #5

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

Similar topics

13
by: ebobnar | last post by:
I've written a link aliasing script that allows users to rewrite urls on their web pages. The crux of the script is the following: if(getimagesize($redirect_to) == 0) header("Location:...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
4
by: Ganesh Kundapur | last post by:
Hi all, suppose i have 100 functions such as f1, f2,...f100 in a single file including main. If i pass arguement to main such as $a.out f1 main should call appropriate functions. I can do this...
8
by: Barkster | last post by:
I have two functions on buttons onclick, they work but if the first fails the second still runs. How can I prevent this? Simplified Code below. Thanks Function Function1 () { if (something)...
2
by: trantanm | last post by:
Hi everybody, I failed to call unmanaged functions in C++ dll from C# application. If I compile and produce the C++ dll file in .NET environment, I can call them from C#. Is the reason that the...
6
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. ...
13
LacrosseB0ss
by: LacrosseB0ss | last post by:
I was wondering, can an OnClick event of a button call multiple functions? The reason for this is I have a page that when "ok" is clicked, goes to a preview page before submitting data to the...
7
by: beginner | last post by:
Hi Everyone, I have encountered a small problems. How to call module functions inside class instance functions? For example, calling func1 in func2 resulted in a compiling error. "my module...
1
by: Ahmad Jalil Qarshi | last post by:
Hi, I am develop a dynamic link library in C on AIX that will internally call java functions using JNI. This libaray will be finally used by other C Executable. There is only one function in...
3
by: chaitanya83 | last post by:
Is it possible to call both events onclick,ondblclick in div tag?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.