Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First off:</p> <pre><code>$('a#hardness_max').click(insert_tag("hardness_max")); // is equivalent to: var tmp = insert_tag("hardness_max"); $('a#hardness_max').click(tmp); // this calls the click handler with the result of the insert_tag function </code></pre> <p>What you probably wanted was:</p> <pre><code>$('a#hardness_max').click(function() { insert_tag("hardness_max"); }); // This function registers the click callback </code></pre> <p>As for the <code>ctr+alt+1</code>, it is the same case, but I would also add the textbox so they can do the shortcut in the textbox:</p> <pre><code>$(document).add('#water_chemistry').bind('keydown', 'alt+ctrl+1', function() { insert_tag("temp_min"); }); </code></pre> <hr> <p>So the final result is:</p> <pre><code>jQuery( document ).ready( function( $ ) { function insert_tag(tag){ $('#water_chemistry').val($('#water_chemistry').val()+' ['+tag+'] '); } var docAndTextarea = $(document).add('#water_chemistry'); docAndTextarea.bind('keydown', 'alt+ctrl+1', function() { insert_tag("temp_min"); }); docAndTextarea.bind('keydown', 'alt+ctrl+2', function() { insert_tag("temp_max"); }); docAndTextarea.bind('keydown', 'alt+ctrl+3', function() { insert_tag("pH_min"); }); docAndTextarea.bind('keydown', 'alt+ctrl+4', function() { insert_tag("pH_max"); }); docAndTextarea.bind('keydown', 'alt+ctrl+5', function() { insert_tag("hardness_min"); }); docAndTextarea.bind('keydown', 'alt+ctrl+6', function() { insert_tag("hardness_max"); }); docAndTextarea.bind('keydown', 'alt+ctrl+7', function() { insert_tag("conductivity_min"); }); docAndTextarea.bind('keydown', 'alt+ctrl+8', function() { insert_tag("conductivity_max"); }); $('a#temp_min').click(function() { insert_tag("temp_min"); }); $('a#temp_max').click(function() { insert_tag("temp_max"); }); $('a#pH_min').click(function() { insert_tag("pH_min"); }); $('a#pH_max').click(function() { insert_tag("pH_max"); }); $('a#hardness_min').click(function() { insert_tag("hardness_min"); }); $('a#hardness_max').click(function() { insert_tag("hardness_max"); }); $('a#conductivity_min').click(function() { insert_tag("conductivity_min"); }); $('a#conductivity_max').click(function() { insert_tag("conductivity_max"); }); }); </code></pre> <hr> <p><strong>And here is the jsFiddle:</strong></p> <p><a href="http://jsfiddle.net/DmP2Q/" rel="nofollow">FIDDLE!</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload