Javascript Php无法检索动态生成的文本字段
我无法检索使用javascript创建的动态生成的文本字段和单选按钮,但能够检索使用html手动添加到表单中的文本字段和单选按钮 以前,我使用样式来隐藏和显示我的所有文本字段,而不是动态创建的文本字段,因此我获取所有文本字段没有问题,并且可以安全地假设我的PHP处理没有任何问题 我的HTML/界面编码Javascript Php无法检索动态生成的文本字段,javascript,php,html,Javascript,Php,Html,我无法检索使用javascript创建的动态生成的文本字段和单选按钮,但能够检索使用html手动添加到表单中的文本字段和单选按钮 以前,我使用样式来隐藏和显示我的所有文本字段,而不是动态创建的文本字段,因此我获取所有文本字段没有问题,并且可以安全地假设我的PHP处理没有任何问题 我的HTML/界面编码 <?php for ($x = 1; $x <= 5; $x++) { $inputAreaID = "inputArea".$x;// Creating all dynami
<?php
for ($x = 1; $x <= 5; $x++)
{
$inputAreaID = "inputArea".$x;// Creating all dynamic options and etc in this div using javascript
$typeID = "type".$x; //for select type id
$opt2ID = "ans".$x;
$optID = "opt".$x;
$comID = "com".$x;
$qnName = "qn".$x // for qn textfield name?>
<table>
<tr>
<td>Question <?php echo $x ?></td>
<td><input type="text" name='<?php echo $qnName ?>' required></td>
</tr>
<tr>
<td>Question Type</td>
<td>
<select id="<?php echo $typeID ?>" name="<?php echo $typeID ?>" onclick="showQuestionSelect('<?php echo $x ?>', '<?php echo $typeID ?>', '<?php echo $inputAreaID ?>')">
<option value="">Please select one option </option>
<option value="Yes,No">Yes/No </option>
<option value="True,False">True/False</option>
<option value="3">A. B. C. D.</option>
</select>
</td>
</tr>
</table>
<div id='<?php echo $inputAreaID ?>' style="margin-bottom: 1px;margin-top:1px;"></div>
问题:
首先,您应该检查服务器是否已获得这些生成的文本字段的值。尝试显示$\u POST[]
的所有成员
我猜你被困在参数的名称中了我已经回显了我的$\u帖子[];但是我没有把它放在上面的代码里。我已经使用这个名称进行了测试,通过硬编码我的html名称并创建“testtextfield”来硬编码gui文件中动态生成的测试的名称。结果能够通过我的处理php代码得到检索。我正在使用innerhtml生成文本字段。这是否会影响我是否能够检索动态生成的文本字段?
function showQuestionSelect(questionNo, typeID, inputArea)
{
var s = String(typeID);
var i = String(inputArea);
var e = document.getElementById(s);
var selectedOpt = e.options[e.selectedIndex].value;
ansID = questionNo + "_ans";
comID = questionNo + "_com";
optA = questionNo + "_optA";
optB = questionNo + "_optB";
optC = questionNo + "_optC";
optD = questionNo + "_optD";
var msg = "";
if (selectedOpt == "True,False")
{
msg ="<div style='margin-bottom: 10px;margin-top:10px;'><input type='radio' name='"+ ansID + "' value='True'> Submit True as Answer<input type='radio' name='" +ansID +"' value='False'> Submit False as Answer</div>";
msg +="<div style='margin-bottom: 10px;margin-top:10px;'>Reason for the answer: <input type='text' name='" + comID + "' value='' /></div>"
}
else if (selectedOpt == 3)
{
msg = "<div style='margin-bottom: 10px;margin-top:10px;'>";
msg += "Option A: <input type='text' name='" + optA + "' value='' /> <input type='radio' name='" + ansID + "' value='" + optA + "'> Submit as Answer <br><br>";
msg += "Option B: <input type='text' name='" + optB + "' value='' /> <input type='radio' name='" + ansID + "' value='" + optB + "'> Submit as Answer <br><br>";
msg += "Option C: <input type='text' name='" + optC + "' value='' /> <input type='radio' name='" + ansID + "' value='" + optC + "'> Submit as Answer <br><br>";
msg += "Option D: <input type='text' name='" + optD + "' value='' /> <input type='radio' name='" + ansID + "' value='" + optD + "'> Submit as Answer </div>";
msg +="<div style='margin-bottom: 10px;'>Reason for the answer: <input type='text' name='" + comID + "' value='' /></div>";
}
document.getElementById(i).innerHTML = msg;
}
for ($x = 1; $x <= 5; $x++)
{
$qn = $_POST["qn".$x]; // for qn textfield name
$type = $_POST["type".$x]; //for select type id
$ans = $_POST[$x."_ans"]; //for answer div id
$reason = $_POST[$x."_com"]; //for answer div id
$optionType = "";//to put into database
if ($type == "Yes,No")
{
$ans = "";
$reason = "";
}
if ($type == "3")
{
$optA = $_POST[$x."_optA"];
$optB = $_POST[$x."_optB"];
$optC = $_POST[$x."_optC"];
$optD = $_POST[$x."_optD"];
$optionType = $optA.",".$optB.",".$optC.",".$optD;
if ($ans == $x."_optA")
$ans = $optA;
else if ($ans == $x."_optB")
$ans = $optB;
else if ($ans == $x."_optC")
$ans = $optC;
else
$ans = $optD;
}
else
$optionType = $type;