简体   繁体   English

HTML表单提交-Ajax生成的下拉值未发送

[英]Html form submit - ajax generated dropdown values not sent

I have a form embedded in a html/smarty template code. 我有一个嵌入在html / smarty模板代码中的表单。 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. 如果更改选项,它将使用ajax通过onChange事件调用php脚本,该ajax创建/填充2个其他下拉列表。 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. 这部分工作正常,但是如果您提交了整个表单(涉及原始下拉菜单和另外两个动态创建的表单),则在有2个动态创建的下拉菜单的情况下,尽管键值对位于内部,但它们根本不会发送到浏览器换句话说,它仅发送包含模板本身的值,而不发送通过ajax生成到“ txtHint1”中的值。

Thnx n

html/template form: html /模板形式:

<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: 通过ajax调用的php代码的一部分:

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>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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