Note that there are some explanatory texts on larger screens.

plurals
  1. POForm elements added dynamically via Jquery only post value when set in value attribute
    primarykey
    data
    text
    <p>I have an html form (generated in php), and if a user select a specific value from a select, extra input fields are added via jQuery.</p> <p>In the processing page, the values for the new fields were not coming through - see an exerpt from phpinfo(): </p> <pre><code>_POST["child"] Array ( [1] =&gt; Array ( [label] =&gt; [id] =&gt; ) [2] =&gt; Array ( [label] =&gt; [id] =&gt; ) [3] =&gt; Array ( [label] =&gt; [id] =&gt; ) [4] =&gt; Array ( [label] =&gt; [id] =&gt; ) [5] =&gt; Array ( [label] =&gt; [id] =&gt; ) ) </code></pre> <p>However, if I set the value attribute in the html that jquery adds, that value comes through. Does anyone have any experience with this issue? </p> <p>Any ideas?</p> <p>Thanks in advance!</p> <p>Edited: Form html: </p> <pre><code>&lt;input type='hidden' name='orderIds' id='orderIds'/&gt; &lt;input type="hidden" name="changeNums" id="changeNums"/&gt; &lt;input type="hidden" name="changeIds" id="changeIds"/&gt; &lt;input type='hidden' name='fromPage' id='fromPage' value='/new/admin/extra_info.php?'/&gt; &lt;input type='hidden' name='table' id='table' value='extra_info'/&gt; &lt;input type="hidden" name="splitPageNum" id="splitPageNum" value=""/&gt;&lt;div align='center'&gt;&lt;div class='popUpS' align='center' id='popUp'&gt;&lt;div align='right' id='closeDiv' class='off' onmouseover="this.className='offOver'" onmouseout="this.className='off'"&gt;&lt;a class='off' href='javascript:closePopUp()'&gt;X&lt;/a&gt;&lt;/div&gt;&lt;div align='center'class='noticeBar'id='noticeBar'&gt;&lt;/div&gt;&lt;br/&gt;&lt;div id='newOrderTr'&gt;&lt;div class='formPrompt'&gt;Order&lt;/div&gt;&lt;div class='formInput'&gt;&lt;select class='formInput' name='orderNumber' id='orderNumber'&gt;&lt;option value=''&gt;-Select-&lt;/option&gt;&lt;option value='1'&gt;Before Select Kashrus&lt;/option&gt;&lt;option value='2'&gt;Before Select Kashrus&lt;/option&gt;&lt;option value='3'&gt;Before Select Kashrus&lt;/option&gt;&lt;option value='4'&gt;After Select Kashrus&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div class="formPrompt"&gt;Active&lt;/div&gt;&lt;div class="formInput"&gt;&lt;select class="formInput" name="Active" id="Active"&gt;&lt;option value=""&gt;-Select-&lt;/option&gt;&lt;option value="Active"&gt;Active&lt;/option&gt;&lt;option value="Inactive"&gt;Inactive&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;&lt;br/&gt;&lt;div class='formPrompt'&gt;Field Label&lt;/div&gt;&lt;div class='formInput'&gt;&lt;input type='text' class='formInput' name='label' id='label'/&gt;&lt;/div&gt;&lt;br/&gt; &lt;div class='formPrompt'&gt;Field Type&lt;/div&gt;&lt;div class='formInput' id='container_fieldType'&gt;&lt;select class='formInput' name='fieldType' id='fieldType'&gt;&lt;option value=''&gt;-Select-&lt;/option&gt; &lt;option value='0'&gt;Short Text&lt;/option&gt;&lt;option value='1'&gt;Long Text&lt;/option&gt;&lt;option value='2'&gt;Drop Down&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;&lt;br/&gt;&lt;div class='formPrompt'&gt;Is Required&lt;/div&gt;&lt;div class='formInput' id='container_isRequired'&gt;&lt;select class='formInput' name='isRequired' id='isRequired'&gt;&lt;option value=''&gt;-Select-&lt;/option&gt; &lt;option value='1'&gt;Yes&lt;/option&gt;&lt;option value='0'&gt;No&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;&lt;br/&gt;&lt;div class='clearFloats' style='width:600px;text-align:center;'&gt;&lt;input type='submit' value='Submit'/&gt;&lt;/div&gt;&lt;/div&gt;&lt;/form&gt; </code></pre> <p>JS:</p> <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt; &lt;script type='text/javascript'&gt; $('#fieldType').bind('change', function(){ if($('#fieldType').val() == 2){ if($('#rowId').val() != 'new'){ getVals($('#rowId').val()); } $('#container_fieldType').after('&lt;div id="child_form"&gt;' + $('#childFormHTML').html() + "&lt;input type='hidden' name='child_table' value='extra_info_values'/&gt;&lt;input type='hidden' name='child_table_fields' value='label'/&gt;&lt;/div&gt;") } else{ if($('#child_form').html()) if(confirm("Do you want to delete all values?")) $('#child_form').remove() } }); function getVals(rowId){ $.get('ajax/getVals.php?rId=' + rowId, function(data) { if(data != ''){ $('#childFormHTML').html(data); } }); } &lt;/script&gt; </code></pre> <p>Html to add:</p> <pre><code>&lt;div id='childFormHTML' style='display:none;'&gt; &lt;br class='clear:both;'/&gt;&lt;div class='formPrompt'&gt;Value&lt;/div&gt; &lt;div class='formInput'&gt;&lt;input type='text' id='child[1][label]' value=' ' name='child[1][label]' class='formInput'/&gt;&lt;input type='hidden' name='child[1][id]'/&gt;&lt;/div&gt; &lt;br class='clear:both;'/&gt;&lt;br class='clear:both;'/&gt; &lt;div class='formPrompt'&gt;Value&lt;/div&gt; &lt;div class='formInput'&gt;&lt;input type='text' id='child[2][label]' value=' ' name='child[2][label]' class='formInput'/&gt; &lt;input type='hidden' name='child[2][id]'/&gt;&lt;/div&gt; &lt;br class='clear:both;'/&gt;&lt;br class='clear:both;'/&gt; &lt;div class='formPrompt'&gt;Value&lt;/div&gt;&lt;div class='formInput'&gt;&lt;input type='text' id='child[3][label]' value=' ' name='child[3][label]' class='formInput'/&gt; &lt;input type='hidden' name='child[3][id]'/&gt;&lt;/div&gt; &lt;br class='clear:both;'/&gt;&lt;br class='clear:both;'/&gt; &lt;div class='formPrompt'&gt;Value&lt;/div&gt; &lt;div class='formInput'&gt;&lt;input type='text' id='child[4][label]' value=' ' name='child[4][label]' class='formInput'/&gt;&lt;input type='hidden' name='child[4][id]'/&gt;&lt;/div&gt; &lt;br class='clear:both;'/&gt;&lt;br class='clear:both;'/&gt; &lt;div class='formPrompt'&gt;Value&lt;/div&gt;&lt;div class='formInput'&gt;&lt;input type='text' id='child[5][label]' value=' ' name='child[5][label]' class='formInput'/&gt;&lt;input type='hidden' name='child[5][id]'/&gt;&lt;/div&gt;&lt;br class='clear:both;'/&gt;&lt;/div&gt; </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.
    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