events and image

A

amit

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="javascript:my_trker('http://www.mywebsite.com/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.
 
R

Randy Webb

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?

what I have done is:

Testing image:
<a href="" name="linkImg1"
onclick="javascript:my_trker('http://www.mywebsite.com/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
 
A

amit

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="javascript:my_trker('http://www.mywebsite.com/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
 
R

Randy Webb

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="javascript:my_trker('http://www.mywebsite.com/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="someFunction(this)" src="..">

function someFunction(imgObject){
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?
 
A

amit

Randy said:
amit said the following on 6/29/2006 5:49 PM:

<img onclick="someFunction(this)" src="..">

function someFunction(imgObject){
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.javascript 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="someFunction(this)" onmouseup="someFunction(this)"
src="..">


Please let me know this as well.

Also, what Javascript book do you suggest?

Thank again
Amit
 
R

Randy Webb

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

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="someFunction(this)" onmouseup="someFunction(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.
 
A

amit

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("protocol") +
"&host=" +
items.get("host") +
"&path=" +
items.get("pagepath") +

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.
 
R

Randy Webb

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? said:
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("protocol") +

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

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 :)
 
A

amit

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

:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top