Based on the current cursor/textbox selected , when the user clicks a button/character I would like the character to be inserted where the cursor is.
Here is a js fiddle example:
JS:
$(document).ready(function () {
$(".buttons").click(function () {
var cntrl = $(this).html();
$("#txt-area1").append(cntrl);//not sure what to use here to "know" where cursor currently is
});
});
HTML:
<textarea id="txt-area1" readonly></textarea>
<textarea id="txt-area2" readonly></textarea>
<textarea id="txt-area3" readonly></textarea>
<textarea id="txt-area4" readonly></textarea>
<div>
<button class="buttons">á</button>
<button class="buttons">é</button>
<button class="buttons">í</button>
<button class="buttons">ó</button>
<button class="buttons">ú</button>
<button class="buttons">ñ</button>
<button class="buttons">ü</button>
</div>
How can I make the above "know" which of the multiple text boxes is selected and insert the character only into this box?
active, when it losses focus remove that class. Then You can append the text box with theactiveclass.