July 28th in Javascript by .

iframe innerHTML value from textarea

If you want to assign value to iframe innerHTML its just easy. All you have to do is just assign the value of the textarea to the iframes innerHTML property. If the value is html source, the iframe will give a rich text look. There may a situation as well if you want to pull mysql html data and format it inside a html editor.

lets say you have a textarea where you have a html code and want to be inserted to iframe to edit inside the rich text editor.

myeditor = document.getElementById('rte').contentWindow.document; 

function LoadData(obj)
{
alert(document.getElementById(obj).value);
myeditor.body.innerHTML= document.getElementById(obj).value;
}

The html code of the page with the form elements.

<form action="" method="post" onSubmit="doCheck('mybox');">
<textarea name="textareabox" id="mybox">This is a <b>bold</b> sample textarea</textarea>
<input type="button" id="btnLoad" onsubmit="LoadData('textareabox')">

</form>

and

    VERY IMPORTANTLY

If you try to set the value of innerHTML of iframe dynamically while still iframe loads, the assigning the value wont work. The above should work because it is called from click button after the iframe has completely loaded.

Similar Posts:

One Comment

  • atasözleri
    February 18, 2010

Leave A Comment.





Please wrap all source codes with [code][/code] tags. Powered by