Enjoy an ad free experience by logging in. Not a member yet?
Register .
11-16-2012, 11:13 AM
PM User |
#1
New to the CF scene
Join Date: Aug 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
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,
11-16-2012, 11:18 AM
PM User |
#2
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
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.
11-16-2012, 03:26 PM
PM User |
#3
New to the CF scene
Join Date: Aug 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
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
11-16-2012, 03:42 PM
PM User |
#4
Regular Coder
Join Date: Mar 2008
Location: London
Posts: 129
Thanks: 1
Thanked 31 Times in 31 Posts
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>
11-16-2012, 10:04 PM
PM User |
#5
Master Coder
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
Thanks: 0
Thanked 498 Times in 490 Posts
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.
11-20-2012, 10:09 AM
PM User |
#6
New to the CF scene
Join Date: Aug 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
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
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 06:02 AM .
Advertisement
Log in to turn off these ads.