473,785 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

events and image


Hi group,

Long story short, I'm new to JavaScript and have started it less than 3
weeks. My question is

1) how can I create a situation that when user clicks on gif or ...
image file an event get triggered?

what I have done is:

Testing image:
<a href="" name="linkImg1"
onclick="javasc ript:my_trker(' http://www.mywebsite.c om/akohan');" >
<img name=img1 src="flower.gif " border=0 >
</a>

the problem is that when I click on this image it goes thru the
function but then the page changes to the path:
http://www.mywebsite.com/akohan and shows a list or directory of the
files I have there!
2) Is it possible to create new events in Javascript? lf so, how can I
monitor an event when user does a right-click on a link or image?

Your help will be appreicated.

amit.

Jun 29 '06 #1
19 1506
amit wrote:
Hi group,

Long story short, I'm new to JavaScript and have started it less than 3
weeks. My question is

1) how can I create a situation that when user clicks on gif or ...
image file an event get triggered?

what I have done is:

Testing image:
<a href="" name="linkImg1"
onclick="javasc ript:my_trker(' http://www.mywebsite.c om/akohan');" >
<img name=img1 src="flower.gif " border=0 >
</a>

the problem is that when I click on this image it goes thru the
function but then the page changes to the path:
http://www.mywebsite.com/akohan and shows a list or directory of the
files I have there!


The reason for that is: href="". If you want to STOP the click from
going through, you need to add return false to your onclick:
onclick = "doSomethin g(); return false"

BTW, 'javascript:' is not needed for onclick

--
"The most convoluted explanation that fits all of the made-up facts is
the most likely to be believed by conspiracy theorists. Fitting the
actual facts is optional."
Jun 29 '06 #2
amit said the following on 6/29/2006 4:36 PM:
Hi group,

Long story short, I'm new to JavaScript and have started it less than 3
weeks. My question is

1) how can I create a situation that when user clicks on gif or ...
image file an event get triggered?
<img onclick="my_trk er('')".....>
what I have done is:

Testing image:
<a href="" name="linkImg1"
onclick="javasc ript:my_trker(' http://www.mywebsite.c om/akohan');" >
<img name=img1 src="flower.gif " border=0 >
</a>

the problem is that when I click on this image it goes thru the
function but then the page changes to the path:
http://www.mywebsite.com/akohan and shows a list or directory of the
files I have there!
Because you navigated there with the link.
2) Is it possible to create new events in Javascript? lf so, how can I
monitor an event when user does a right-click on a link or image?


onmousedown, onmouseup, and onclick

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 29 '06 #3

Thanks Tony,

I appreciate your help. can you tell me what is the format for a image
tag which is clickable?

The following tag is clickable but it doesn't pass the name and path of
the file!

Testing image:
<a href="" name="linkImg1"
onclick="javasc ript:my_trker(' http://www.mywebsite.c om/akohan');" >
<img name=img1 src="flower.gif " border=0 >
</a>

I need to pass some information i.e path, filename to a function.
Any clue?

Thanks,
amit


Tony wrote:
amit wrote:
Hi group,

Long story short, I'm new to JavaScript and have started it less than 3
weeks. My question is

1) how can I create a situation that when user clicks on gif or ...
image file an event get triggered?

what I have done is:

Testing image:
<a href="" name="linkImg1"
onclick="javasc ript:my_trker(' http://www.mywebsite.c om/akohan');" >
<img name=img1 src="flower.gif " border=0 >
</a>

the problem is that when I click on this image it goes thru the
function but then the page changes to the path:
http://www.mywebsite.com/akohan and shows a list or directory of the
files I have there!


The reason for that is: href="". If you want to STOP the click from
going through, you need to add return false to your onclick:
onclick = "doSomethin g(); return false"

BTW, 'javascript:' is not needed for onclick

--
"The most convoluted explanation that fits all of the made-up facts is
the most likely to be believed by conspiracy theorists. Fitting the
actual facts is optional."


Jun 29 '06 #4
amit said the following on 6/29/2006 5:49 PM:
Thanks Tony,

I appreciate your help. can you tell me what is the format for a image
tag which is clickable?

The following tag is clickable but it doesn't pass the name and path of
the file!

Testing image:
<a href="" name="linkImg1"
onclick="javasc ript:my_trker(' http://www.mywebsite.c om/akohan');" >
<img name=img1 src="flower.gif " border=0 >
</a>

I need to pass some information i.e path, filename to a function.
Any clue?


<img onclick="someFu nction(this)" src="..">

function someFunction(im gObject){
alert(imgObject .src)
}

You pass it by reference.

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 29 '06 #5

Randy Webb wrote:
amit said the following on 6/29/2006 5:49 PM:
Thanks Tony,

I appreciate your help. can you tell me what is the format for a image
tag which is clickable?

The following tag is clickable but it doesn't pass the name and path of
the file!

Testing image:
<a href="" name="linkImg1"
onclick="javasc ript:my_trker(' http://www.mywebsite.c om/akohan');" >
<img name=img1 src="flower.gif " border=0 >
</a>

I need to pass some information i.e path, filename to a function.
Any clue?


<img onclick="someFu nction(this)" src="..">

function someFunction(im gObject){
alert(imgObject .src)
}

You pass it by reference.

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/



Hello Randy,

Thanks a lot! it was a big help but it like anyother answer takes me to
new things which I need to learn. First, I hope I'm putting this text
in a proper sequence if not let me know then.

What I asked and you mentioned works for single click but a proper of
doing this is to capture mousedown and mouseup events. To make sure
user has clicked (both down and up ) on a link or a image or etc.

How can I simulate that? is it to code like:

<img onmousedown="so meFunction(this )" onmouseup="some Function(this)"
src="..">
Please let me know this as well.

Also, what Javascript book do you suggest?

Thank again
Amit

Jun 30 '06 #6
amit said the following on 6/30/2006 7:13 PM:

<snip>
Hello Randy,

Thanks a lot! it was a big help but it like anyother answer takes me to
new things which I need to learn. First, I hope I'm putting this text
in a proper sequence if not let me know then.
It is fine.
What I asked and you mentioned works for single click but a proper of
doing this is to capture mousedown and mouseup events.
Why?
To make sure user has clicked (both down and up ) on a link or a image or etc.

How can they click up without first clicking down?
How can I simulate that? is it to code like:

<img onmousedown="so meFunction(this )" onmouseup="some Function(this)"
src="..">

Precisely.
Please let me know this as well.

Also, what Javascript book do you suggest?


None. They all suck that I have seen to date. Most are outdated and over
priced. For learning, use the archives of this group and you won't ever
go wrong.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 30 '06 #7

Hi Randy,

Thanks for your true response. I have looked at most of them and they
are kinda same thing! except some brief topics.

Ok, I want to ask you anothe question! as you have seen I have been
doing capturing information about a user in terms of what he/she has
been doing like right click or simple click on different components on
a page such as links, image and .... then need to send it to a web
serivec or application (server side) to store all user's activity into
a database.

Currently what I'm doing is storing some information i.e. protocol,
hostname, referrer and also the path of the current page and what
element is clicked/right clicked on into an object such as image!!!!
I'm having a feeling that this is odd and there must be a better way to
store it and send it to the server instead of using image object.

My code is like:

var myvar = new Image(1,1);

/*
capture some info
*/
myimg.src = base "?protocol= " + items.get("prot ocol") +
"&host=" +
items.get("host ") +
"&path=" +
items.get("page path") +

after assignment then I have :

myimg.onload = function()
{
return;
}
of course, it is working since the web service captuers it but I need
to know if there is a better way to send these information to the
sever.

Thank again Randy and I wish you wonderful 4th of July.

Randy Webb wrote:
amit said the following on 6/30/2006 7:13 PM:

<snip>
Hello Randy,

Thanks a lot! it was a big help but it like anyother answer takes me to
new things which I need to learn. First, I hope I'm putting this text
in a proper sequence if not let me know then.

It is fine.
What I asked and you mentioned works for single click but a proper of
doing this is to capture mousedown and mouseup events.

Why?
To make sure user has clicked (both down and up ) on a link or a image or etc.


How can they click up without first clicking down?
How can I simulate that? is it to code like:

<img onmousedown="so meFunction(this )" onmouseup="some Function(this)"
src="..">

Precisely.
Please let me know this as well.

Also, what Javascript book do you suggest?

None. They all suck that I have seen to date. Most are outdated and over
priced. For learning, use the archives of this group and you won't ever
go wrong.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 3 '06 #8
amit said the following on 7/3/2006 2:01 PM:
Hi Randy,

Thanks for your true response. I have looked at most of them and they
are kinda same thing! except some brief topics.
Even the ones about not top-posting? <g>
Ok, I want to ask you anothe question! as you have seen I have been
doing capturing information about a user in terms of what he/she has
been doing like right click or simple click on different components on
a page such as links, image and .... then need to send it to a web
serivec or application (server side) to store all user's activity into
a database.
That sounds suspiciously like snooping but ok.
Currently what I'm doing is storing some information i.e. protocol,
hostname, referrer and also the path of the current page and what
element is clicked/right clicked on into an object such as image!!!!
Ummm, ok, if you say so. hostname isn't that critical unless you have a
server that will server up the same document from different domains.
I'm having a feeling that this is odd and there must be a better way to
store it and send it to the server instead of using image object.
It is very odd indeed.
My code is like:

var myvar = new Image(1,1);
/*
capture some info
*/
myimg.src = base "?protocol= " + items.get("prot ocol") +
You are missing a + between base and "?
"&host=" +
items.get("host ") +
"&path=" +
items.get("page path") +

after assignment then I have :
So far so good.
myimg.onload = function()
{
return;
}
That code is un-needed as it doesn't do anything.

of course, it is working since the web service captuers it but I need
to know if there is a better way to send these information to the
sever.
Don't fix what isn't broken. And you have about the most reliable way to
do what you are doing.
Thank again Randy and I wish you wonderful 4th of July.
Good thing I am American.... Don't tell Jews to have a Merry Christmas :)
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 4 '06 #9

Hi Randy,

I appreciate your patience and reading all my statements one by one and
answering them!

1) As you saw, I was using an image object to send those tokens or
information! Is there any better way (something that makes sense) ?
2) I'm coming from C/C++ programming background and I think there
should be ways to do javascript programming base on OO techniques.
Right?
if so, do you know any link?
3) I'm sure you have heard of AJAX. Do you recommend it to learn?
Thanks again,
Amit

:)



Randy Webb wrote:
amit said the following on 7/3/2006 2:01 PM:
Hi Randy,

Thanks for your true response. I have looked at most of them and they
are kinda same thing! except some brief topics.

Even the ones about not top-posting? <g>
Ok, I want to ask you anothe question! as you have seen I have been
doing capturing information about a user in terms of what he/she has
been doing like right click or simple click on different components on
a page such as links, image and .... then need to send it to a web
serivec or application (server side) to store all user's activity into
a database.

That sounds suspiciously like snooping but ok.
Currently what I'm doing is storing some information i.e. protocol,
hostname, referrer and also the path of the current page and what
element is clicked/right clicked on into an object such as image!!!!

Ummm, ok, if you say so. hostname isn't that critical unless you have a
server that will server up the same document from different domains.
I'm having a feeling that this is odd and there must be a better way to
store it and send it to the server instead of using image object.

It is very odd indeed.
My code is like:

var myvar = new Image(1,1);
/*
capture some info
*/
myimg.src = base "?protocol= " + items.get("prot ocol") +

You are missing a + between base and "?
"&host=" +
items.get("host ") +
"&path=" +
items.get("page path") +

after assignment then I have :

So far so good.
myimg.onload = function()
{
return;
}

That code is un-needed as it doesn't do anything.

of course, it is working since the web service captuers it but I need
to know if there is a better way to send these information to the
sever.

Don't fix what isn't broken. And you have about the most reliable way to
do what you are doing.
Thank again Randy and I wish you wonderful 4th of July.

Good thing I am American.... Don't tell Jews to have a Merry Christmas :)
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 5 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3049
by: Roger Shrubber | last post by:
I have a page with images that the user can drag from one frame to another. I need them to see a "ghost image" of the image they are dragging, while the original stays put. I use the onmousemove event to keep the ghost image under the mouse pointer. There are three problems: (1) if the ghost image is dragged so it is partially off the edge of the screen, scrollbars appear. This not only looks bad, it can cause the page to autoscroll...
0
993
by: ChrisN | last post by:
Howdy, I'm writing a web application in VB.Net. I'm using C# for all of the dynamic content on the vb pages. I'm currently building a VB page that displays a table of pictures. The page calls a C# object that populates a table with images and a couple of linkButtons for deleting and editing the images. So the table is embedded into the page and looks like this (this part works fine): Edit Delete
4
22891
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on when to use one over another? If anyone could provide any additional info, your comments, best practices, any good articles, specific examples, etc. Thank you
5
2128
by: Jeff Ptak | last post by:
Can anyone tell me how to trap mouse click events in the Image control? I am trying to implement an image zoom feature using JavaScript where the user could "draw" a zoom box (aka rubber band box) on the image and the image would zoom to the extents of the box. Anyone know how to accomplish this?
3
2304
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace WebApplication1 { using System;
1
5802
by: Nathan Sokalski | last post by:
I want to create a pushbutton-like control on my webform that has an image on it. I used to think that this is what the ImageButton control was, but it seems to me that the ImageButton is nothing more than an image that can be clicked. I have figured out a way to make the ImageButton look like a button (there was some border property and the backgroud color). However, that still does not make it look like it is being "pushed" the way other...
1
1663
by: Tebogo Tefo via .NET 247 | last post by:
Hi I have a user control that contains three dropdownlists that I populate according to what was selected in the other dropdownlist (i.e. populate dropdownlist2 after selecting a value in dropdownlist1) The App works fine if I don't add the user control that I created and all events on the page work and thus the App is perfect. But as soon as I add my user control (Here used as the TopNav for my page) all
0
1461
by: StriderBob | last post by:
In a simple two form project, use a button on each form to Show() the other form and Hide() the current form. Add MouseEnter and MouseLeave events to both buttons so they change the image on each button when they are NOT Clicked but the cursor enters their boundary. This setup works fine. If the mouse cursor enters the button on the first form the image changes and if the button is clicked the first form disappears and the other form...
9
2319
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables using attributes in the *.aspx page. Everything displays great for the initial load, but whenever I try to add or delete an item (I have controls to do this on the page), it does not seem to be recieving any values for the public variables. Here is...
7
3448
by: MasterMax1313 | last post by:
I'm trying to make a grid of picture box controls, which I do via code. Each of these boxes has a mouseclick, mousedown, mouseup, and mouseenter event. The mouseclick event is simple enough and works fine. However, i use the mousedown, mouseup, and mouseenter events to be able to click and drag to apply the same image across all of the boxes the mouse enters (similar to a terrain editor for a game like StarCraft). I set a form wide boolean...
0
9480
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
10325
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
10147
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
10091
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
9950
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...
0
8972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
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...
1
4050
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
2879
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.