Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-16-2012, 11:13 AM   PM User | #1
bu06nne
New to the CF scene

 
Join Date: Aug 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
bu06nne is an unknown quantity at this point
Combining two onclick js functions

Hi folks,

I need to add an onclick function to a submit button for a form that was built by a developer.

How would I do this, if the submit button already has an onclick function already there?

<div id="formbuttons"><input class="buttonsubmit" id="btnsubmit" name="btnsubmit" onclick="return formvalidate()" type="submit" value="Send"/> </div>
<input type="hidden" name="subaction" value="form" /> <input type="hidden" name="formId" value="OnlineFormHandler"/></form>


I need to add the following to the submit button:

onclick="wrs_trackclick('DCS.dcsuri=formsubmit', 'WT.ti=form submit','WT.dl=24')

Many thanks,
bu06nne is offline   Reply With Quote
Old 11-16-2012, 11:18 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
<div id="formbuttons"><input class="buttonsubmit" id="btnsubmit" name="btnsubmit" onclick="return formvalidate(); wrs_trackclick('DCS.dcsuri=formsubmit', 'WT.ti=form submit','WT.dl=24')" type="submit" value="Send"/> </div>
"Most of the time I don't have much fun. The rest of the time I don't have any fun at all."- oody Allen - US movie actor, comedian, & director (1935 - )
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 11-16-2012, 03:26 PM   PM User | #3
bu06nne
New to the CF scene

 
Join Date: Aug 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
bu06nne is an unknown quantity at this point
Thanks for your swift response...

Unfortunately that code doesn't seem to work.

The form validation part works, but the Webtrends analytics code part doesn't seem to be firing off...

Any ideas what it could be?

Many thanks,

Nick
bu06nne is offline   Reply With Quote
Old 11-16-2012, 03:42 PM   PM User | #4
niralsoni
Regular Coder

 
Join Date: Mar 2008
Location: London
Posts: 143
Thanks: 3
Thanked 38 Times in 38 Posts
niralsoni is an unknown quantity at this point
It didn't worked because the onclick code is prefixed with "return" keyword, which will return after completing the first function, and won't execute the second function.

if your validation function is returning true or false then try this out -

Code:
<div id="formbuttons"><input class="buttonsubmit" id="btnsubmit" name="btnsubmit" onclick="if(formvalidate()) {wrs_trackclick('DCS.dcsuri=formsubmit', 'WT.ti=form submit','WT.dl=24'); return true;} return false;" type="submit" value="Send"/> </div>
niralsoni is offline   Reply With Quote
Old 11-16-2012, 10:04 PM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
You could swap the function calls around the other way assuming they are independent of one another.

Code:
<div id="formbuttons"><input class="buttonsubmit" id="btnsubmit" name="btnsubmit" onclick="wrs_trackclick('DCS.dcsuri=formsubmit', 'WT.ti=form submit','WT.dl=24'); return formvalidate(); " type="submit" value="Send"/> </div>
This is an example of why it is better to use event listeners in JavaScript rather than event handlers - you would have been able to add a second submit listener without needing to update any of the already existing code.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is online now   Reply With Quote
Old 11-20-2012, 10:09 AM   PM User | #6
bu06nne
New to the CF scene

 
Join Date: Aug 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
bu06nne is an unknown quantity at this point
Thanks for both your replies.

Unfortunately neither of them worked, the form validates, but the webtrends javascript function doesn't fire off. Any ideas what I should I do now?

Cheers,
Nick
bu06nne is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:43 PM.


Advertisement
Log in to turn off these ads.