[thelist] [javascript (IE) ] setting designMode for multiple editable iframes

Paul Bennett paul at teltest.com
Thu Jul 24 18:38:59 CDT 2003


hmm, not sure about that subject line, but here goes....

I am altering a javascript rich-text editor which uses the IE 
proprietary execCommand methods.
I wish to add a number of instances of the editor to a page - have thge 
following code for an initialisation for each editable iframe that us 
used for rich text editing:
iframes are named: iBody_1, iBody_2 and so forth
hidden textareas that contain the database text to be edited are named: 
contentBody_1, contentBody_2 and so forth.

function init()
    {
     // number of instances of editor on page
    var instances = 2;
    // counter      
    var i;
    // set design mode,a nd place database text into iframe for each 
instance on page
    for(i=1; i<=instances; i++)
        {
        // format iframe name
        var i_name = 'iBody_'+i+'';
        i_name = i_name.toString();
        // THIS NEXT LINE BREAKS THE SCRIPT

        i_name.document.designMode = 'On';

        // fomat hidden textarea (containing document text to be edited) 
name
        var textarea_name = 'contentBody_'+i+'';
        // get the text from this textarea
        innerTmp = document.forms[0].elements[textarea_name].value;
        // format command for setTimeout method
        var command = i_name+".document.body.innerHTML = innerTmp;"
        // place this text into the iframe, timeout is to give the 
scripot time to perform these actions
        setTimeout(command,500);
        }
     }

The error I get from IE6 is : "document is null or not an object" for 
the line which sets the desing mode to on. I can hardcode the iframe id 
into the line and the script will execute without error. I can comment 
the line and the script will execute without error (only the iframe text 
is not editable, as designMode has not been set!)
What is stopping a variable name (i_name) from working successfully on 
the design mode line, as opposed to a hardcoded value?

Am I making sense?

-- 
 ------------------------------
	Paul Bennett						
	Internet Developer				
	Teltest Electronic Design		
 ------------------------------			
Email: paul at teltest.com				
Phone: 64 4 237 4557					
Web: http://www.teltest.com		
Wap: http://wap.teltest.com			




More information about the thelist mailing list