July 28th in Javascript by .

iframe value to textbox in javascript

iframe componenet in javascript can provide a rich text editing and a html page can be easily embeeded inside iframe as it is just like frames.

<iframe id="edior" width="300" height="200 style="border:0px solid grey"></iframe>

To remove the border both in IE and firefox you can set the style to 0px.

You can also load the iframe dynamically with javascript

document.write("<iframe id=\"rte\" width=\"" + width + "\" height=\"" + height + "\" style=\"border:1px solid grey\"></iframe>");

But what if you want to send a value from iframe to a textbox in a form through POST. The idea is along with iframe include a hidden input box and get the iframe innerHTML value assigned to hidden input when the form is submitted. iFrames innerHTML will return the html source to the hidden textbox value

window.onload = function()
{
myeditor = document.getElementById('rte').contentWindow.document;
myeditor.designMode = "on";
}

function doSubmit(txtbox) {
document.getElementById('hiddenbox').value = myeditor.body.innerHTML;
}

The html page is below.

<form action="" method="post" onSubmit="doSubmit();">
<input type="hidden" id="hiddenbox" name="hiddenbox">
</form>

Similar Posts:

2 Comments

  • atasözleri
    February 18, 2010
  • Reviews
    August 2, 2010

Leave A Comment.