How to create HTML Form in a new window
<p>I have the following function:</p>

<pre><code>// open a new window. Create and submit form
function createSubmitForm(response) {
    var external = window.open('about:blank', 'external');
    var doc = external.document;
    var body = $('body', doc);

    // create a new form element
    var form = $("&lt;form id='authForm'&gt;&lt;/form&gt;");
    // set the form's attributes and add to iframe
    form.attr("action", response.action)
        .attr("method", response.method);
    form.appendTo(body);

    // create form elements;
    for (var i = 0, len = response.fields.length; i &lt; len; i++) {
        var field = response.fields[i];

        if (field.name != "") {
            $("&lt;input type='hidden'/&gt;")
                .attr("name", field.name)
                .attr("value", field.value)
                .appendTo(form);
        }
    }
    // submit the form
    form.submit();
}
</code></pre>

<p>When I try to execute it, I get an <strong>"Unspecified Error"</strong> at <code>form.appendTo(body)</code>. </p>

<p>What could I be doing wrong here?</p>
