View Full Version : How to set focus to textarea
mwdelta
23rd December 2007, 01:50 AM
Been using the registered version for a couple months now and am pretty happy. We’ve been able to work around most of the issues we’ve come up with so far, except this one.
I need to be able to set the focus to textarea fields using Javascript. The standard method of object.focus() doesn’t work. I’m assuming there is a JS function in the source code to start editing in the iframe, but I have not been able to find it.
This is holding up our deployment, so can anyone help?
staff
2nd January 2008, 10:31 AM
Not sure of an exact solution, but make sure that the object you're sending the focus() to is the correct object. JSpell Evolution will substitute iframes for your regular text elements (to enable spell check as you type).
mwdelta
4th January 2008, 03:54 AM
Well, I can't set focus to the textarea, because it has been hidden and replaced by the iframe editor. And trying to focus() the iframe using the code below doesn't seem to have any effect:
function jspellPostInit() {
var jspellEditor = jspellAreaLookup(document.getElementById("entry_5"));
jspellEditor.focus();
}
Looking at the page with a DOM inspector, I don't see anything else to set the focus to. The only controls are the hidden textarea and the iframe editor.
I've come to the conclusion that either you're using a custom javascript function to start editing (i.e. show the cursor) in the iframe editor when the mousedown event is triggered, or this functionality is somehow built into the iframe specification (but I see no evidence of that in MSDN and other documentation).
If you could tell me what function is triggered when a user clicks in the iframe editor to start typing, I believe calling that function would perform the same action as .focus() on a textarea object.
Does this clarify my situation a bit?
ddaland
21st April 2008, 02:53 PM
jspellArea=jspellAreaLookup(document.getElementByI d("LAST")).contentWindow.document;
jspellArea.body.focus();
I've been able to set focus on the IFrame this way.
I'm looking for a way to change the background color of the IFrame or highlight the data within the IFrame. I can see all the style properties but I don't seem to be able to change them. If anyone has any ideas, please share.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.