[英]Why Can't I Select Dynamically (PHP) Generated Options?
I am having an issue with a table where each cell contains an id'd input or select field. 我在一个表格中有一个问题,其中每个单元格都包含一个id输入或选择字段。 The cell contents are dynamically generated from a MySQL query. 单元格内容是通过MySQL查询动态生成的。 Everything works fine except for my dynamically generated SELECT drop downs. 除了我动态生成的SELECT下拉列表以外,其他所有功能都正常运行。 I am using the following code in a switch statement: 我在switch语句中使用以下代码:
case 'crew_1':
case 'crew_2':
echo '<td><select class="'.classExt($types[$key]).' '. $key .'_c" id="' . $key . '--' . $idx .'">';
echo '<option value="" selected="selected"></option>';
while ($rowtech = mysqli_fetch_assoc($rtech)){
echo '<option value="' . $rowtech['name'] . '">' . $rowtech['name'] . '</option>';
} mysqli_data_seek($rtech,0);
echo '<option value="TEST">TEST</option>';
echo '</select></td>'; break;
This creates the following HTML: 这将创建以下HTML:
<td>
<select class="varchar crew_1_c" id="crew_1--1">
<option value="" selected="selected"></option>
<option value="Name 1">Name 1</option>
<option value="Name 2">Name 2</option>
<option value="TEST">TEST</option>
</select>
</td>
From this I can select the blank or 'TEST' option and it returns the correct value in a console.log, but if I choose one of the dynamically generated names, the box returns back to the default blank value. 从中,我可以选择空白或“测试”选项,它会在console.log中返回正确的值,但是如果我选择动态生成的名称之一,则该框将返回到默认的空白值。 I get the same responses on Chrome and IE. 我在Chrome和IE上得到了相同的响应。
Where is my disconnect? 我的断线在哪里?
Included for the person requesting the script generating to output to console: 包括请求脚本生成以输出到控制台的人员:
$('tbody select, tbody input').change(function(){
console.log($(this).val());
});
OP, you're missing the name
attribute. OP,您缺少name
属性。 This works fine for me: 这对我来说很好:
<form method="post" action="">
<select class="varchar crew_1_c" id="crew_1:1" name="choice">
<option value="" selected="selected"></option>
<option value="Name 1">Name 1</option>
<option value="Name 2">Name 2</option>
<option value="TEST">TEST</option>
</select>
<input type="submit" value="Submit" name="submit" />
</form>
<?php
var_dump($_REQUEST);
?>
Found my issue. 找到了我的问题。 The JS request earlier had me dig back through my code to discover that I was setting my values toUpperCase() for submission for consistency, but that was breaking my value match on the drop down. 之前的JS请求让我回溯了我的代码,发现我将我的值设置为UpperCase()以进行提交以保持一致性,但是这在下拉列表中破坏了我的值匹配。 I set my values to uppercase in the select options also and TA-DA! 我还在选择选项和TA-DA中将值设置为大写!
Thanks for the help, guys. 谢谢大家的帮助。 Sometimes it takes a fresh pair of eyes to point out the obvious. 有时需要新鲜的眼睛指出明显的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.