![]() |
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, |
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> |
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 |
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> |
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> |
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 |
| All times are GMT +1. The time now is 04:42 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.