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.
我有一个嵌入在html / smarty模板代码中的表单。在表单内部有一个下拉框,其中包含从db填充的选项。如果你改变一个选项,它会通过onChange事件调用一个php脚本,使用ajax创建/填充2个下拉列表。这部分工作正常,但是如果您提交整个表单(包括原始下拉列表和2个其他动态创建的表单),在2个动态创建的下拉列表的情况下,键值对不会发送到浏览器,尽管它们在里面换句话说,它只发送包含模板本身的值,而不是通过ajax生成“txtHint1”的值。
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:
通过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>";
2 个解决方案
#1
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>";
#2
I think you also need an ... So you would want:
我想你也需要...所以你会想要:
echo "<select name='datet_selection" . $fieldID . "'><option>Test</option></select>";
#1
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>";
#2
I think you also need an ... So you would want:
我想你也需要...所以你会想要:
echo "<select name='datet_selection" . $fieldID . "'><option>Test</option></select>";