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

635 views
Skip to first unread message

amrit pal pathak

unread,
Oct 10, 2010, 3:22:26 AM10/10/10
to v8-users
i have two file
1)Html=which has html code..
2).js file which has 2 functions

Problem);;i want when i click the image , .js file(its fucntions)
should be called and image should be resized according to the code..
But what i am doing ,it is not being doing

1)contents of html file is as under


<html>
<body>

<body onload="changeIt();">
<head>

<script langauge="javascript">

function changeIt()
{

var width=50;
var height=50;
document.image.width=width
document.image.height=height


}

</script>
</head>


<img src="/home/administrator/Desktop/aa.jpeg" name="image"
onclick=src="/var/www/external.js/changeeIt();">

</body>
</html>


2)Content of .js file is as under



function changeeIt()

{
if(count==1)
{
var width=500
var height=500
document.image.width=width
document.image.height=height
count=2;
}
else if(count==2)
{
var amrit1=50
var pal=50
document.image.width=amrit1
document.image.height=pal
count=1;

}


}




Please somebody help

Thanks in advance

ionlupascu

unread,
Oct 10, 2010, 6:42:03 AM10/10/10
to v8-users
If you look by this address:
http://www.w3schools.com/tags/tag_script.asp
the corrected html code should be:
-------------------------------------------------------------------------
<html>
<body onload="changeIt();">
<head>
<script langauge="javascript">
function changeIt(){
var width=50;
var height=50;
document.image.width=width
document.image.height=height
}

</script>
<script langauge="javascript" src="external.js"/>
</head>
<img src="aa.jpg" name="image" onclick="changeeIt1();">
</body>
</html>
-------------------------------------------------------------------------
and external.js file:
-------------------------------------------------------------------------
var count=1;
function changeeIt1(){
if(count==2){
var amrit1=50
var pal=50
document.image.width=amrit1
document.image.height=pal
count=1;
}else{
var width=500
var height=500
document.image.width=width
document.image.height=height
count=2;
}
}
-------------------------------------------------------------------------

Hope if this helps you.

On Oct 10, 10:22 am, amrit pal pathak <amritpalpath...@gmail.com>
wrote:

amritpal pathak

unread,
Oct 10, 2010, 10:03:31 AM10/10/10
to v8-u...@googlegroups.com
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users








This is not working ,i follwed the same as it is... even now image is not showing..
i want to call function changeeIt() when image is clicked
Help
Thanx

 

amritpal pathak

unread,
Oct 10, 2010, 10:05:44 AM10/10/10
to v8-u...@googlegroups.com
- Show quoted text -
Thanks for reply but this is not working ..

ionlupascu

unread,
Oct 10, 2010, 10:59:55 AM10/10/10
to v8-users
On Oct 10, 5:03 pm, amritpal pathak <amritpalpath...@gmail.com> wrote:
> On Sun, Oct 10, 2010 at 6:42 AM, ionlupascu <ionlupa...@gmail.com> wrote:
>
> This is not working ,i follwed the same as it is... even now image is not
> showing..

change the image name from "aa.jpg" to "aa.jpeg".

> i want to call function changeeIt() when image is clicked
> Help
> Thanx

You should call different image name. e.g. "changeeIt()" on load and
"changeeIt1()" on click. The alternative variant is to call the same
function but set parameter to know when is load and when is click.

In the end, your question is not related by v8 specific.

amritpal pathak

unread,
Oct 10, 2010, 11:57:19 AM10/10/10
to v8-u...@googlegroups.com
Again to u i changed the name of image from "aa.jpg" to "aa.jpeg" .but nothing helped.
m again giving the final coding..

1)coding of html is
<html>
       <body onload="changeIt();">
               <head>
                       <script langauge="javascript">
                               function changeIt(){
                                       var width=50;
                                       var height=50;
                                       document.image.width=width
                                       document.image.height=height
                               }

                       </script>
                       <script langauge="javascript" src="/var/www/external.js"/>
               </head>
               <img src="/home/administrator/Desktop/aa.jpeg" name="image" onclick="changeeIt();">
       </body>
</html>


2)coding of .js file




var count=1;
function changeeIt(){

       if(count==2){
               var amrit1=50
               var pal=50
               document.image.width=amrit1
               document.image.height=pal
               count=1;
       }else{
               var width=500
               var height=500
               document.image.width=width
               document.image.height=height
               count=2;
       }
}

 i am unable to find the error .. please give the solution to these..














--
Reply all
Reply to author
Forward
0 new messages