我需要更多的输入标签,而我的 HTML/JavaScript 组合不起作用
I need more input tags, and my HTML/JavaScript combo isn't working
我的测试站点在 http://grocerylistcalculator.site11.com/grocerycalculator.html# 当然,代码可以在视图源代码中找到。PHP 脚本如下:
<?php
include 'header.html';
$prices = $_POST['price'];
$quantities = $_POST['numbe'];
$total = 0;
foreach ( $prices as $key => $p ) {
$total += $p * $quantities[$key];
}
print "The total is ". $total;
include 'footer.html';
?>
注意:PHP不是我写的,而是在不同的问题上提供的。代码本身有效,但我需要能够添加更多输入部分。JavaScript 在页面上。
所以有这个(编辑以创建div,而不是输入(:
function addInput(divName){
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "Price of entry " + (counter + 1) + "<input type='number' name='price[]' step='any'> <br>Number of said entry: <input type='number' name='numbe[]' step='any'>";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}
但是您在没有参数的情况下调用它:
<p><a href="#" onClick="addInput()">Add a new input section</a><br/></p>
所以首先解决这个问题。然后你可以担心其余的。
此外,请确保将它们添加到form
更新:在表单中,在提交按钮之前,创建一个空div 并将该 ID 传递给
onlclick
函数,如下所示: onClick="addInput('div_id_here')"
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 无法将数据从firebase获取到我的html页面
- 我的HTML按钮没有在Javascript中运行
- 如果使用javascript函数屏幕太小,我该如何更改HTML文件的背景色
- 我的html有一些错误
- 为什么jquery悬停在jsfiddle中可以工作,而在我的html布局中却不能
- 为什么我的短信没有弹出?CSS,HTML
- 为什么<p>没有插入到我的html中
- 如何在我的html网页中使用jquery自动完成
- <text区域>在我的html中包含event.keycode==13之后,wrap就不起作用了
- 我的html表单无法验证.请参阅代码片段中的html代码和java脚本
- 如何重定向到我的html网站youtube嵌入视频打开在youtube应用程序
- 为什么我的html页面没有在<ui视图>
- 在将javascript附加到我的html中时遇到问题
- 当按下箭头键时,我的图像以一种奇怪的方式跳跃(HTML+JS)
- 如何在HTML表单中提交我的下拉选择
- 我制作html网站的一小部分——我有一个javascript部分
- 为什么我得到的是返回的[object HTML ParagraphElement]而不是我的号码
- Javascript崩溃HTML -我的代码不工作,你能看到任何错误吗?
- 对象 HTML 我的第一个代码中的错误