It took a bit of mess, as this is a strange problem, but here is the solution I came up with.
I made the textarea inside modal, hidden from view, and will capture any typed command while the modal is open. When the user closes the modal mode, the focus returns to the real text area.
HTML (slightly modified):
<div class="container"> <form> <div class="form-group"> <label>Answer (<a id="showProblemLink" href="#">view problem</a>) </label> <textarea id="outside-modal" class="form-control" rows="7"> </textarea> </div> </form> <div id="problemModal" class="modal" tabindex="-1" role="dialog" data-backdrop="false"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-body"> <p> The local school wants a new playground. The lot they can use for the playground is shaped like a rectangle. The school has decided to let the students design the new playground. The students have decided that they want 1/4 of the playground to be a football field. Another 3/8 of the lot will be used for a basketball court. How much of the lot is remaining for the slides and swings? </p> <textarea id="inside-modal"></textarea> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div>`
CSS
textarea#inside-modal { position:absolute; left:-4000px; }
JQuery
$("#showProblemLink").on("click", function() { //show the modal $('#problemModal').modal('show'); //fill the hidden textarea with the real textarea contents $('#problemModal textarea#inside-modal').val($('textarea#outside-modal').val()); //capture user input in modal and send to outside textarea $('#problemModal textarea#inside-modal').on('input',function(e) { //fill the outside textarea with the inside textarea contents $('textarea#outside-modal').val($('textarea#inside-modal').val()); }).focus(); }); //when modal closed, send focus back to textarea $("#problemModal").on('hidden.bs.modal',function() { $('textarea#outside-modal').focus(); });
See this bootply
source share