prototype/ajax really simple Event.observe question

D

Doug Lerner

Sorry if this is so basic...

Right now in my code I have the following Event.observe statement:

Event.observe($('msg'), 'keypress', txKeyPressHandler, true);


This works fine: if a key is pressed in the "msg" field the
txKeyPressHandler function is invoked and makes an asynchronous call to the
server and all is fine.

What I want to do is something similar, but with clicks ordinary links that
I have generated dynamically.

So there might be:

link1
link2
link3

etc., with some identifying parameters along with each link.

Right now I have these links, but I am just clicking on them which opens up
a little window that displays the results coming back from the server. That
works fine, functionally.

But I would like, instead, to click on them and invoke an asynchronous call,
like I am doing above with the "msg" field, so I can just smoothly display
my results right there without opening up another window.

Should I:

1. Include an onclick to javascript which calls the click handler in each
link? If so, what is the proper syntax for this?

or

2. Should I have an Event.observe statement that checks for click events on
the links? If so, what should the <a> tag parameters be? For example, does
each link need its own "id" parameter? Can an Event.observe observe more
than one id at a time? Or is there some other way I should do this, like
observe clicks and then somehow determine which element was clicked on from
that and what its parameters are?

Which way do you think is better?

Thanks!

doug
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top