[英]Inserting value from span tag into SQL database
I have a form filled with 24 checkboxes that a user fills in, underneath these checkboxes I have 2 span tags. 我有一个填写有24个复选框的表单,用户可以在其中选中2个span标签。 One counts how many are checked, and the other displays what percentage it is.
一个计算要检查的数量,另一个显示要检查的百分比。 When I submit this form, I get the following error: Undefined index: #countcheckboxes in
D:\\inetpub\\wwwroot\\SMT_24_Point_Check\\newAudit.php on line
33
提交此表单时,出现以下错误:未定义索引:第33行的
D:\\ inetpub \\ wwwroot \\ SMT_24_Point_Check \\ newAudit.php中的#countcheckboxes
These are my span tags at the bottom of the form... 这些是表格底部的我的span标签...
<div class="count-checkboxes-wrapper">
Total score: <span id="count-checked-checkboxes"
name="countcheckboxes">0</span> out of 24 checked
</div><br>
<!-- button to show div below -->
<input type="button" value="Show Audit Score" onclick=showDiv()>
<!--div showing total audit score as percentage-->
<div id="percentDiv"; style="display:none;" class="percentage-checkboxes-
wrapper">
Audit Result:<span id="percentage-checked-checkboxes"
name="percentagecheckboxes"> 0</span> %
</div>
On the newAudit.php page, this is the post tags I have for those 2 span tags... 在newAudit.php页面上,这是我为这2个span标签设置的post标签...
$totalChecked = $_POST['countcheckboxes'];
$auditScore = $_POST['percentagecheckboxes'];
The out put from the checkboxes displays: Total score: 2 out of 24 checked And after 'show audit score' is clicked, it says 'Audit result: 8%. 复选框的输出显示:总分:24个已检查中的2个。单击“显示审核分数”后,显示“审核结果:8%”。 I need the values of 2 and 8% to be inserted into the database.
我需要将2和8%的值插入数据库。
There are lot of options for you to get the values rather that using meaningless name
attribute over span
. 有很多选项可让您获取值,而不是在
span
使用无意义的name
属性。
data-count
attribute over both divs ie, count-checked-checkboxes
and percentagecheckboxes
. data-count
属性,即count-checked-checkboxes
和percentagecheckboxes
。 With the same function, that update the counts, do update the data-attributes. let checkCount = $('#count-checked-checkboxes').attr('data-count');
let checkCount = $('#count-checked-checkboxes').attr('data-count');
获得这些值let checkCount = $('#count-checked-checkboxes').attr('data-count');
and so on. let checkCount = $('#count-checked-checkboxes').val()
and so on. let checkCount = $('#count-checked-checkboxes').val()
来获取值let checkCount = $('#count-checked-checkboxes').val()
上。 let checkCount = $('#count-checked-checkboxes').text()
and so on. let checkCount = $('#count-checked-checkboxes').text()
等来使用跨度的文本值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.