Reputation: 1753
I have the code below
<script>
$(document).ready(function(){
//function showChar(){
shortcut.add("Ctrl+F1", function()
document.activeElement.id.value +="text";
});
var counter=0;
setInterval(function() {
for(int i=0;i<4;i++){
var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
newTextBoxDiv.after().html('<div><label style="float:left;"></label></div><pre><textarea name="textbox' + counter + '" id="textbox" ><%=rsta2.getString("data")%></textarea></pre>');
newTextBoxDiv.appendTo("#TextBoxesGroup");
counter++;
}
CKEDITOR.replace( 'textbox'+i+'',
{
toolbar :
[
['Source'],
['Bold','Italic','Underline','Strike'],
],
height: 300,
width: 700
});
},1000);
});
</script>
<div id='TextBoxesGroup'>
<div id="TextBoxDiv0">
</div>
</div>
The above code(minus the ckeditor part of the code) adds 4 textareas,depending on which textarea is active when I press ctrl+f1
text
is added to that particular textarea.But when I replace textarea with ckeditor the shortcut keys dont work.What should I do?
Upvotes: 1
Views: 136
Reputation: 785
Replace your shortcut function with this:
shortcut.add("Ctrl+F1", function() {
var $active_textarea = $('textarea:focus');
var current_value = $active_textarea.val();
$active_textarea.val(current_value + "text");
});
Upvotes: 1
Reputation: 21536
You want to get the textarea that has focus, you can use
$('textarea:focus').val(paste_text);
that should do it.
Upvotes: 1