Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I didn't test extensively, but this seems to work:</p> <p>(I found the "insertAtCursor" function at <a href="http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript#comment-3817" rel="noreferrer">http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript#comment-3817</a>)</p> <pre><code>&lt;textarea id="text-area" rows="20" cols="100"&gt;&lt;/textarea&gt; &lt;script&gt; document.getElementById("text-area").onkeydown = function(e) { if (!e &amp;&amp; event.keyCode == 9) { event.returnValue = false; insertAtCursor(document.getElementById("text-area"), " "); } else if (e.keyCode == 9) { e.preventDefault(); insertAtCursor(document.getElementById("text-area"), " "); } }; //http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript#comment-3817 function insertAtCursor(myField, myValue) { //IE support if (document.selection) { var temp; myField.focus(); sel = document.selection.createRange(); temp = sel.text.length; sel.text = myValue; if (myValue.length == 0) { sel.moveStart('character', myValue.length); sel.moveEnd('character', myValue.length); } else { sel.moveStart('character', -myValue.length + temp); } sel.select(); } //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); myField.selectionStart = startPos + myValue.length; myField.selectionEnd = startPos + myValue.length; } else { myField.value += myValue; } } &lt;/script&gt; </code></pre> <p><strong>EDIT</strong>: Modified the script so it doesn't use jQuery.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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