Here is my javascript:
$(document).ready(function(){
$(".reply").click(function(){
var replyId = $(this).attr("id");
$("textarea[name='comment']").val("<reply:"+replyId+">");
$("textarea[name='comment']").ready(function(){
moveCursorToEnd($(this));
});
});
});
function moveCursorToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}
I am somewhat new to functions with javascript however this does not seem to work It will put the value in but not focus to the textarea. I am sure I am doing something very dumb, any ideas?
The ready event for the textarea will not fire because once the event is attached the textarea has already been loaded. Also you must also pass the raw element, not the jQuery object into the function. Try to changing these lines
to this