[英]How to prevent inserting value greater than the number which user enters in text field
I had a text field called premium where the user can enter max of 10 digits.After they click submit another text field called deposit opens where it can enter a max of 7 digits..But I want to give a condition where the user cant enter the deposit more than premium.. Example: 我有一个名为premium的文本字段,用户可以输入最多10位数字。单击提交后,另一个名为deposit的文本字段可以输入最多7位数字。但是我想给用户一个不能输入的条件存款多于溢价。示例:
If premium=111 Deposit should be <=111
If the deposit is more than premium onchange the value should be changed back to premium ie, to 111 如果保证金大于更改时的溢价,则应将值改回溢价,即更改为111
Can someone help me in this I got stuck. 有人可以帮我解决这个问题。 Thanks.
谢谢。 Jsfiddle for above: https://jsfiddle.net/U3pVM/28556/
上面的Jsfiddle: https ://jsfiddle.net/U3pVM/28556/
Kindly check once and upvote if you find it helpful 请检查一次并赞成,如果发现有帮助
https://jsfiddle.net/U3pVM/28558/ https://jsfiddle.net/U3pVM/28558/
function TodoCtrl($scope) {
$scope.hide=false;
$scope.submit = function() {
$scope.hide=true;
if($scope.deposit && parseInt($scope.deposit)>parseInt($scope.premium)){
$scope.deposit = $scope.premium;
}
};
}
hi you can add tyr with following code as a attribute to deposit input field. 您好,您可以使用以下代码将tyr作为属性添加到存款输入字段。 And give id "preminum" to premium input field.
并将ID“ preminum”赋予高级输入字段。
onkeypress="return Number(this.value()+""+event.key) <= Number($('#premium').value());"
This won't allow user to enter value more than premium. 这将不允许用户输入超过溢价的值。
Add this code: 添加此代码:
$scope.$watch('deposit', function(newVal, oldVal){
if(newVal && newVal*1 > $scope.premium*1)
$scope.deposit = $scope.premium;
})
Html5 supports min and max with number inputs. HTML5支持带有数字输入的最小和最大。 For example:
<input type="number" name="deposit" min="1" max="111">
Anyway it is good to check all user inputs on server side. 例如:
<input type="number" name="deposit" min="1" max="111">
无论如何,最好检查服务器端的所有用户输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.