I use the script to sum the input value, and it works. However, and when I click up and down the "input#total_selfmark" does not change, and when I type the number, the "input#total_selfmark" changes and the number is no restriction. Even I have set the min=0 max =$task_criteria->maximummark
<div class="form-group">
{{ Form::number('selfmark','',['placeholder'=>'', 'class' =>'selfmark', 'min'=>'0','max'=>$task_criteria->maximummark]) }}
</div>
Here is the script
$(document).ready(function() {
//this calculates values automatically
calculateSum();
$(".selfmark").on("keydown keyup", function() {
calculateSum();
});
});
function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$(".selfmark").each(function() {
//add only if the value is number
if (!isNaN(this.value) && this.value.length != 0) {
sum += parseFloat(this.value);
$(this).css("background-color", "#FEFFB0");
} else if (this.value.length != 0) {
$(this).css("background-color", "red");
}
});
$("input#total_selfmark").val(sum.toFixed(2));
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
We miss some HTML here!
[<>]and post a minimal reproducible example with RENDERED HTML and relevant script (jQuery version matters too - yours is ANCIENT)[<>]snippet editor. Please click edit, scroll down and click "edit the above snippet" and add relevant HTML, not template - also use$(".selfmark").on("input", calculateSum).trigger("input");