I have a value in an attribute named (data-max-value) which is currently set to 2.00000
The code below is trying to remove the .000000, leaving just 2 in this case.
Cant get this below to work.
var pointValueMaxScore = $(this).attr("data-max-value");
var pointValueMaxScoreRounded = $(pointValueMaxScore).html(Math.floor($(pointValueMaxScore).html()));
This is the whole function, so it gives it some perspective.
$(document).on("click", "#txtNewQuestionChoiceScore", function () {
var pointValueMaxScore = $(this).attr("data-max-value");
var pointValueMaxScoreRounded = $(pointValueMaxScore).html(Math.floor($(pointValueMaxScore).html()));
var pointValueCurrentScore = $(this).val();
console.log(pointValueMaxScoreRounded);
if (pointValueCurrentScore === pointValueMaxScoreRounded) {
$(this).prop('disabled', true);
}
});
Basically the way I have it is once for example 2 = 2 I disable the input type number field, which works, but then the user hasnt the option to change 2 to 1.
How can I stop the incrementation option, once it gets to the cut off point, but allows the user to decrease the value.
This is how it is at the moment, but its not able to detect once 2 equals to 2 and then stop them counting up further.
$(document).on("click", "#txtNewQuestionChoiceScore", function () {
var pointValueMaxScore = $(this).attr("data-max-value");
var pointValueMaxScoreRounded = Math.floor(pointValueMaxScore);
var pointValueCurrentScore = $(this).val();
console.log(pointValueMaxScoreRounded);
console.log(pointValueCurrentScore);
if (pointValueCurrentScore >= pointValueMaxScoreRounded) {
$("#txtNewQuestionChoiceScore").prop('disabled', true);
} else {
$("#txtNewQuestionChoiceScore").prop('disabled', false);
}
});
This is my input field
<input class="number-input questionChoiceScoreInput textBoxSizeFullWidth textSizeStandard text-input formElement text-box single-line" data-decimal-places="5" data-max-value="2.00000" data-required="true" data-val="true" data-val-number="The field Score must be a number." id="txtNewQuestionChoiceScore" name="Score" type="number" value="" autocomplete="off" >
So what I have done now is stripped that function away, and on success load of the form added these few lines which stops the user entering anything they want in there, and also restricts the increment option on the number field, as below.
$("#txtNewQuestionChoiceScore").keydown(function (evt) {
evt.preventDefault();
});
var pointValueMaxScore = $("#txtNewQuestionChoiceScore").attr("data-max-value");
var pointValueMaxScoreRounded = Math.floor(pointValueMaxScore);
$("#txtNewQuestionChoiceScore").attr({
"max": pointValueMaxScoreRounded,
"min": 0
});