I haven't found a solid answer to this (other than doing a custom tpl for each form; which seems tedious).

Is there a quicker way to add custom elements, like javascript (onclick), into ?

e.g.

<input id="edit-submit" class="form-submit" type="submit" value="Submit" name="op" onclick="tracking('track_submit_quote')"/>

Thank you for your time.

Comments

duntuk’s picture

EDIT:

submission form stripped fields... this is what i wrote:

Is there a quicker way to add custom elements, like javascript (onclick), into <submit/>?

duntuk’s picture

Version: 6.x-2.8 » 6.x-2.9
quicksketch’s picture

You can do this by adding a markup component on your page and including the JavaScript there, such as this:

$(document).ready(function() {
  $('#edit-submit').click(function() { tracking('track_submit_quote'); });
});

Just make sure that you use the Full HTML input format so that it doesn't get stripped out by the Filtered HTML filter.

duntuk’s picture

Thank you quicksketch, I was about to post my similar solution which i just learned.

Here's what I ended up using :

<?php
 
drupal_add_js( '

$(function () { // make this code initialize when DOM loads
	$("#edit-submit").submit(function () { // optional: replace "#edit-submit" with whatever CSS selector you want (ex: Form, ID or class)
		tracking("track_submit_quote"); // add custom function here
	});
});

;','inline');

?>

(it's basically the same thing except it uses 'drupal_add_js' which puts the code in 'head' and uses 'submit' instead of 'click' ... not entirely sure if there is different end result for forms here, i know 'click' works with links also...)

quicksketch’s picture

Status: Active » Closed (fixed)