Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamically created form depending on <select> does not work
    primarykey
    data
    text
    <p>I'm developing a website which must display particular forms for various products depending on the value that the user selects (in <code>&lt;select&gt;</code>) - so a number various forms are created dynamically in a loop by means of a javascript function (<code>buildform()</code> ). The code does not work, e.g. the forms are not created/appended to the wrappers. I narrowed down the problem where i think the problem relates to a different values for the jquery selectors/div-id's <code>(#ecorpproductwrapper"+ecorp_eprodselectid)</code>. When I use (just as a test) <code>#ecorpproductwrapper"</code> (without the variable <code>ecorp_eprodselectid;</code> see also in code below under ALTERNATIVE WORKS) the code works fine, e.g. the forms are built. I checked by means of the console that the <code>ecorpproductwrapper"+ecorp_eprodselectid</code> values are the same for the div-id's and jquery selectors, so I dont understand what goes wrong?</p> <p>Pls see the simplified code below:</p> <pre><code>for(var i=0;i&lt;5;i==){ var ecorp_eprodselectid; //will have various values //function to build form depending on selected value in &lt;select class= eprodtype"+ecorp_eprodselectid &gt; $(".eprodtype"+ecorp_eprodselectid).focus(function () { var previous; // Store the current value on focus and on change previous = this.value; //old select value }).change(function() { var optionsform = buildform(this.value); console.log('append form'+optionsform); //NEXT 2 lines doe NOT WORK $("#ecorpproductwrapper"+ecorp_eprodselectid).children().remove(); //remove previous form $("#ecorpproductwrapper"+ecorp_eprodselectid).append(optionsform); //ALTERNATIVE works: $('#ecorpproductwrapper').children().remove(); //remove previous tariif struct form //ALTERNATIVE works: $('#ecorpproductwrapper').append(optionsform); var str = "#ecorpproductwrapper"+ecorp_eprodselectid; console.log('STRING ECORP PRODUCT APPEND: '+str); console.log('change eprod val: '+this.value); previous = this.value; });//$("").focus(function () { }//for i //function to build form var buildform = function(ecorp_eproductid) { //some code here //NEXT LINE does not work: form += '&lt;td&gt; &lt;div id="ecorpproductwrapper'+ ecorp_eprodselectid+'"&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt;'; //cell with wrapper for ecorp product info //ALTERNATIVE WORKS: form += '&lt;td&gt; &lt;div id="ecorpproductwrapper"&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt;'; //cell with wrapper for ecorp product info //some code here; returns form }//function buildform </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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