简体   繁体   中英

Html form submit - ajax generated dropdown values not sent

I have a form embedded in a html/smarty template code. Inside a form there is a dropdown box with options populated from db. If you change an option, it calls a php script via onChange event using ajax that creates/populates 2 further dropdowns. This part works fine, but if you submit the whole form (involving original dropdown and the 2 further dynamically created ones) in case of 2 dynamically created drop-downs the key-value pairs are simply not sent to the browser despite that they are inside the tags as well.In other words it sends only the values contained the template itself and not the ones generated into "txtHint1" via ajax.

Thnx

html/template form:

<table border="0" width="600">
<tr>
<form name='form1' id='form1' method='get' action=''>
<td width="80"><h4><b>Source 1:</b></h4></td>
<td>
<select name='host_selection' onChange="showDatet(this.value,'txtHint1')">
{foreach from=$hostlist item="entry"}
<option value={$entry.host}>{$entry.host}</option>
{/foreach}
</select>
</td>
<td>
<div id="txtHint1">
</div>
</td>
</tr>
<tr>
<td>
<button type='submit' name='Submit'>COMPARE!</button>
</td>
<td>
<input type='hidden' name='op' value='hid' />
</td>
</form>
</tr>
</table>

part of php code called via ajax:

echo "<select name='datet_selection" . $fieldID . "'>Test</option>";
foreach ($x->sql->record as $temp) {
    echo "<option value='" . $temp['datet'] . "'>" . $temp['datet'] . "</option>";
}
echo "</select>";   

This may not solve the entire problem, but the dropdowns your are dynamically rendering do not appear to be well-formed. Change:

echo "<select name='datet_selection" . $fieldID . "'>Test</option>";

to

echo "<select name='datet_selection" . $fieldID . "'><option>Test</option>";

我认为您还需要一个...因此,您需要:

echo "<select name='datet_selection" . $fieldID . "'><option>Test</option></select>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM