我正在创建一个表单,并且我添加了一个按钮来创建动态文本框 bt 当我在创建动态文本框后提交表单时,我没有从文本框中得到任何输出
echo '<form action="" method="post">';
echo '<INPUT size=70% TYPE="hidden" VALUE="AIzaSyxxxxxxxxxx" NAME="apiKey">';
echo "<INPUT size=70% TYPE = 'hidden' VALUE='xx' NAME = 'registrationIDs'>";
echo '<table class="table" name ="table">';
for($i=0;$i<$counter;$i++){
$srno=$i+1;
echo "<tr name='input-holder'>";
echo " <td><input type='text' value=' $medicsarray[$i] - $qtyarray[$i]'
name='medic'/>"; echo "</td>";
echo "<td><input type='text' name='add[]' /> </td> ";
echo "</tr>";
}
echo "</table>";
}}
?>
<table class="table">
<tr><td><input type='button' name='addmedic' value='add new input box' /></td>
<td></td></tr>
<tr><td>TOTAL:</td><td><input type='text' id='results' value="0"></td></tr>
</table>
<input type="submit" value="Send Notification"/>
</form>
我的 JavaScript 代码
function bindFunctions() {
var sub = document.getElementsByName("addmedic")[0];
sub.onclick = onClickFunction;
var input = document.getElementsByName("add[]");
for (var i = 0; i < input.length; i++) {
if (input[i].type == "text") {
input[i].onblur = onBlurFunction;
}
}
}
bindFunctions();
function onBlurFunction() {
var ttl = 0;
var input = document.getElementsByName("add[]");
for (var i = 0; i < input.length; i++) {
if (input[i].type == "text") {
ttl += Number(input[i].value);
}
}
res =document.getElementById("results");
res.value=ttl;
}
function onClickFunction() {
var inputHolder = document.getElementsByName('table');
var a= inputHolder.length;
a=a-1;
inputHolder[a].innerHTML +="<tr name='input-holder'><td><input type='text'
name='medic' placeholder='medicine name and qty' /></td><td><input type='text'
name='add[]'/></td></tr>";
bindFunctions();
}
</script>
<pre>
<?php print_r($_POST); ?>
</pre>
当我不单击添加文本框按钮时输出 [添加] => 数组([0] => 23 [1] => 23)