[英]How do I enable my submit button after the totaled value of my inputs reaches 50?
I am trying to enable the submit button after the total value of my fields reaches 50. Each field has a different quantity value, the first one is 5, the second 10 and the third 25. When The user inputs a number it is multiplied by the quantity and then added to the total. 我试图在我的字段的总值达到50后启用提交按钮。每个字段都有不同的数量值,第一个为5,第二个为10,第三个为25。当用户输入一个数字时,该值将乘以数量,然后加到总数中。 I am trying to enable the submit button once the total reaches 50. I tried to use a key up function to change the disabled value of the button that targets the total but nothing seems to work.
我试图在总数达到50后启用“提交”按钮。我试图使用向上键功能更改以总数为目标的按钮的禁用值,但似乎无济于事。 I stripped out the code that doesnt work, so now I am back at square one.
我删除了无效的代码,所以现在我回到了第一方。
Here is the fiddle 这是小提琴
http://jsfiddle.net/mdiadmin/TJ7VL/1/ http://jsfiddle.net/mdiadmin/TJ7VL/1/
HTML: HTML:
<table>
<tr>
<th>How many units did you sell?</th>
<th></th>
<th></th>
</tr>
<tr class="txtMult">
<td>
<input name="txtEmmail" class="val1" />
</td>
<td> <span class="val2">How many ball joints? (5 laps per unit)</span>
</td>
<td></td>
</tr>
<tr class="txtMult">
<td>
<input name="txtEmmail" class="val1" />
</td>
<td> <span class="val3">How many struts? (10 laps per unit)</span>
</td>
<td></td>
</tr>
<tr class="txtMult">
<td>
<input name="txtEmmail" class="val1" />
</td>
<td> <span class="val4">How many total undercar assemblies? (25 laps per unit)</span>
</td>
<td></td>
</tr>
<tr>
<td colspan="3" align="left">Total Laps <span id="grandTotal">0.00</span>
<br>
<input id="sbmt" type="submit" name="Submit" value="Submit" disabled>
</td>
</tr>
</table>
Javascript: 使用Javascript:
$(document).ready(function () {
$(".txtMult input").keyup(multInputs);
function multInputs() {
var mult = 0;
// for each row:
$("tr.txtMult").each(function () {
// get the values from this row:
var $val1 = $('.val1', this).val();
var $val2 = 5;
var $val3 = 10;
var $val4 = 25;
var $total = ($val1 * 1) * ($val2 * 1)
$('.multTotal',this).text($total);
mult += $total;
});
$("#grandTotal").text(mult);
}
});
if (mult >= 50){
$("#sbmt").removeAttr("disabled");
}
$("#grandTotal").text(mult);
I suppose you would like to disable the button after the value is once again under the threshold: 我想您想在该值再次低于阈值后禁用该按钮:
$(document).ready(function () {
$(".txtMult input").keyup(multInputs);
var submitButton = $('#sbmt');
var grandTotal = $("#grandTotal");
function multInputs() {
var mult = 0;
// for each row:
$("tr.txtMult").each(function () {
// get the values from this row:
var $val1 = $('.val1', this).val();
var $val2 = 5;
var $val3 = 10;
var $val4 = 25;
var $total = ($val1 * 1) * ($val2 * 1)
$('.multTotal',this).text($total);
mult += $total;
});
if(mult >= 50) {
submitButton.removeAttr('disabled');
} else {
submitButton.attr('disabled', 'disabled');
}
grandTotal.text(mult);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.