If I have a modal dialog which looks like the following, how can I focus the textarea after opening the dialog?
By simply adding $('#txtArea').focus();
after the code, the txtArea
has focus for only a moment.
var popupDiv = document.createElement('div');
popupDiv.innerHTML += '<textarea id="txtArea"></textarea><br/><br/>';
popupDiv.innerHTML += '<button onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, $(\'#txtArea\').val());">OK</button>';
SP.UI.ModalDialog.showModalDialog({
html: popupDiv,
title: '',
allowMaximize: false,
showClose: true,
autoSize: true,
dialogReturnValueCallback: function () { ... }
}