faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

65 of 96 people (68%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How can I get the content of a dynamic IFRAME (edit zone) into a FORM variable to be submitted?

Aug 12th, 2001 18:13
Aaron Fransen, Nicolas Dollo,


Actually this is pretty easy.
The first thing you want to do is change the "Submit" button for the 
form to a plain button that calls some Javascript.
Old "Submit" button:
  <input type=submit name='Submit' value='Send'>
New button:
  <input type='button' name='Submit' value='Send' onclick="Save()">
You'll also need a hidden field:
  <input type='hidden' name='text' value=''>
Make sure the hidden field (and the button!) are within your form tags. 
The hidden field is going to contain the contents of the IFRAME after 
you click the button, so that's the variable name you want to watch for 
in your application (in the above example, "text").
Now you need to create the Javascript "Save" routine to copy the 
contents of the IFRAME to the hidden form field:
function Save() 
    {
    document.compose.text.value = MyIFRAMEName.document.body.innerHTML;
    document.forms['myformname'].submit();
    }
MyIFRAMEName is the name of your IFRAME tag.
myformname is the name of your form.
That should work like a charm. At least in IE. Naturally neither NN or 
Opera support IFRAME as an editing window...