The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. January 09, 2009, 05:51:26 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Multiple "On[C]Lick" actions  (Read 343 times)
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« on: November 06, 2008, 05:07:59 AM »

Hi all,

As many of you know I'm a JavaScript neophyte! So I was hopign someone could help me out with a quick question - where you have a method call associated with an onClick attribute of an image, is it possible to add multiple method calls?

The call currently looks like this:

Code:
onclick="echoc2c.open(); return false;"

Any help much apprecaited.

Cheers,

DM
« Last Edit: November 07, 2008, 01:34:00 PM by DangerMouse » Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 679



View Profile
« Reply #1 on: November 06, 2008, 07:07:03 AM »

Sure, you can have multiple method calls. Just use ; to separate them.

Also be aware of the order they will be executed and also be aware that I've had unexpected results doing things this way, for what it's worth.
Logged

perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5326


:sniffle: Humor was so much easier before.


View Profile
« Reply #2 on: November 06, 2008, 08:56:44 AM »

OnClick (as with all event pops) is just a place to put javascript. You can place whole scripts there if you want, which is what VS is referring to.

This is completely valid: onClick="alert('this'); alert('that'); alert('another');"

... however it's really bad form. Pro mode would be onClick="myFunction()" which has everything you want to do in it.
Logged

If I can't be Mr. Root then I don't want to play.
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« Reply #3 on: November 06, 2008, 09:48:30 AM »

I'm not sure I'm quite ready for pro mode  Wink, would creating a function be as simple as:

Code:
function myFunction() {

// Call analytics software to register a fake page view - indicating link has been clicked

// Open horrible pop up thingy
echoc2c.open();

}

// Execution
onclick="myFunction(); return false;"

Thanks for the tips guys.

DM
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5326


:sniffle: Humor was so much easier before.


View Profile
« Reply #4 on: November 06, 2008, 10:03:13 AM »

Pretty durn close DM. I'd modify just a titch:

Code:
function myFunction()
{
// Call analytics software to register a fake page view - indicating link has been clicked
// ( I assume you'll put that code here...

// Open horrible pop up thingy
echoc2c.open();

return false;
}

// Execution
onclick="myFunction()"

Logged

If I can't be Mr. Root then I don't want to play.
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« Reply #5 on: November 07, 2008, 08:34:14 AM »

Cheers Perk, that's just what I needed.

I'm starting to hate having to ammend other peoples crappy code, wouldnt have any of the problems I'm having now if so called 'web developers' had implemented things properly.

Anyway, I digress in to a rant.

Thanks again,

DM
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5326


:sniffle: Humor was so much easier before.


View Profile
« Reply #6 on: November 07, 2008, 09:31:32 AM »

Rant away, mouse-man. I've never been accused of holding my tongue... Wink
Logged

If I can't be Mr. Root then I don't want to play.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 679



View Profile
« Reply #7 on: November 07, 2008, 12:11:59 PM »

I've been accused of holding your tongue though.
Logged

vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 679



View Profile
« Reply #8 on: November 07, 2008, 12:13:03 PM »

...or maybe it was "tongueing your hole".

I can't remember.

The roofies will do that.
Logged

jammaster82
Expert
****
Offline Offline

Posts: 300

bloody hacker


View Profile WWW
« Reply #9 on: November 07, 2008, 12:18:20 PM »

...or maybe it was "tongueing your hole".

I can't remember.

The roofies will do that.

ROFLMAO - roofies

hahah can we change the subject to multiple on 'lick' events then?

 ROFLMAO ROFLMAO ROFLMAO
Logged

Of course Big Brother exists, he is the embodiment of the party..... Does he exist in the same way I exist?....... You, do not exist.
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« Reply #10 on: November 07, 2008, 01:35:47 PM »

hahah can we change the subject to multiple on 'lick' events then?
 ROFLMAO ROFLMAO ROFLMAO

The way that just had me laughing, I don't see why not!

DM
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!