【发布时间】:2019-01-22 10:31:34
【问题描述】:
我有几个文本框供用户输入数值,这是用 JavaScript 计算总数。
问题是当我需要将数据插入我的数据库时,总数为NULL。我知道这是客户端脚本。
这是我的表格:
<tr>
<th>Normal time</th>
<td><input name="normal_monday" value="" onblur="findTotalmonday()" onkeyup="calculateTotal()" class="normaltime text-center" type="text" size="2" id="normaltime"></td>
<td><input name="normal_thus" value="" onblur="findTotalthus()" onkeyup="calculateTotal()" class="normaltime text-center" type="text" size="2" id="normaltime"></td>
<td><input name="normal_wens" value="" onblur="findTotalwens()" onkeyup="calculateTotal()" class="normaltime text-center" type="text" size="2" id="normaltime"></td>
<td><input name="normal_thu" value="" onblur="findTotalthu()" onkeyup="calculateTotal()" class="normaltime text-center" type="text" size="2" id="normaltime"></td>
<td><input name="normal_fri" value="" onblur="findTotalfri()" onkeyup="calculateTotal()" class="normaltime text-center" type="text" size="2" id="normaltime"></td>
<td><input name="normal_sat" value="" onblur="findTotalsat()" onkeyup="calculateTotal()" class="normaltime text-center" type="text" size="2" id="normaltime"></td>
<td><input name="normal_sun" value="" onblur="findTotalsun()" onkeyup="calculateTotal()" class="normaltime text-center" type="text" size="2" id="normaltime"></td>
<td><input name="normaltimetotal[]" value="" onkeyup="calculateTotal()" class="normaltimetotal text-center" type="text" size="2" id="totaltime1" readonly></td>
</tr>
这是我的 JS:
function findTotalmonday(){
var arr = document.getElementsByName('monday');
var tot=0;
for(var i=0;i<arr.length;i++){
if(parseInt(arr[i].value))
tot += parseInt(arr[i].value);
}
document.getElementById('totalmonday').value = tot;
}
这是我的控制器:
$userData = array(
'name' => $this->input->post('name'),
'employee_code' => $this->input->post('employee_code'),
'weekno' => $this->input->post('weekno'),
'startdate' => $this->input->post('startdate'),
'enddate' => $this->input->post('enddate'),
'normal_mon' => $this->input->post('normal_monday'),
'normal_thus' => $this->input->post('normal_thus'),
'normal_wens' => $this->input->post('normal_wens'),
'normal_thu' => $this->input->post('normal_thu'),
'normal_fri' => $this->input->post('normal_fri'),
'normal_sat' => $this->input->post('normal_sat'),
'normal_sun' => $this->input->post('normal_sun'),
'normal_time_total' => $this->input->post('normal_time_total'),
);
这是错误:
(name, employee_code, weekno, startdate, enddate, normal_mon, normal_thus, normal_wens, normal_thu, normal_fri, normal_sat, normal_sun, normal_time_total, created, modified)
VALUES ('Werner', 'WPR', '2019-W04', '2019-01-22', '2019-01-22', '8', '8', '8', '8', '8', '8', '', NULL, '2019-01-22 11:16:39', '2019-01-22 11:16:39')
现在他们是改变我的代码工作的方法还是有更简单的方法来实现这一点?
【问题讨论】:
-
这就是错误。 (
name,employee_code,weekno,startdate,enddate,normal_mon,normal_thus,normal_wens,normal_thu,normal_sat,normal_sat,normal_sat,normal_sat987654338@,created,modified) 值('Werner','WPR','2019-W04','2019-01-22','2019-01-22','8','8' , '8', '8', '8', '8', '', NULL, '2019-01-22 11:16:39', '2019-01-22 11:16:39')跨度> -
你的问题可以edit,不要在cmets中添加信息
-
你的元素
id="totalmonday"在哪里? -
嗨,阿里。它在表格的另一部分。我有一个女巫正在总结周一的所有工作,
标签: javascript sql codeigniter