The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 10:53:23 AM

Login with username, password and session length


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

Posts: 244



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: 1669



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

hai
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



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

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
DangerMouse
Expert
****
Offline Offline

Posts: 244



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
*****
Offline Offline

Posts: 10096



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

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
DangerMouse
Expert
****
Offline Offline

Posts: 244



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
*****
Offline Offline

Posts: 10096



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

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



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

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

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

Posts: 1669



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

hai
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« 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

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
DangerMouse
Expert
****
Offline Offline

Posts: 244



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!