Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should just re-create the form every time a fresh form is needed.</p> <p>Also, don't get Elements by ID. This is a slow DOM operation and can fail. IDs are recommended for static HTML, so CSS and Javascript can be pointed to it.</p> <p>Instead of getElementsByID, just keep a reference to it in your Javascript code if you need it at all. (I assume you need it to extract the form data on submission).</p> <p>A trivial example (I'm sorry for using jquery here, but it's a lingua franca anyway):</p> <pre><code>var inputs = { givenname: $('&lt;input type="text"&gt;') , surname: $('&lt;input type="text"&gt;') , age: $('&lt;input type="select"&gt;') , gender: $('&lt;select&gt;') .append($('&lt;option&gt;').text('Female').val(0)) .append($('&lt;option&gt;').text('Male').val(1)) .append($('&lt;option&gt;').text('Other').val(2)) } var form = $('&lt;div class="myform"&gt;'); Object.keys(inputs).forEach(function(k) { form.append(inputs[k]); }); function getdata() { var o = {} Object.keys(inputs).forEach(function(k) { o.k = inputs[k].val(); }); return o; } popupFunction(form, getdata); </code></pre> <p>The (to be created) function <code>popupFunction</code> can then just move the form somewhere (<code>mycontainer.append(form)</code>), and when the data should be submitted, extract the data using the getdata function.</p> <p>Note the references I've spoken of are held in the <code>inputs</code> object. They're not direct DOM node references, but references to jquery objects, which in turn hold the DOM nodes, whose value can be extracted with the jquery <code>val()</code> function.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload