My JavaScript code was working well because I received some fantastic solutions here yesterday. I am now wondering if I can enhance this JavaScript with another query. Currently, the query triggers an alert when the number is greater than 199, and it is functioning perfectly.
Now, I am curious to know if I can implement a confirm box for the same input box when I type in a number larger than 100. For instance, if I input the number 110, I would like a confirm box to appear with some information, and if I click Yes, the number should remain in the input box. However, if I enter 200 or a number larger than that, I should still receive the alert notifying me that the number is too big.
Below is the code that I received yesterday for triggering an alert when the number is greater than 199:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page</title>
<script type="text/javascript">
function minMax() {
var min = 0;
var mid = 99;
var max = 199;
var num = parseInt(document.getElementById('value_one').value);
if (num > mid && num < max) {
var r = confirm(num + ' n\'is greater than ' + mid+ '. Press Yes to retain it.');
if (r == false) document.getElementById('value_one').value = "";
return false;
}
if (min > num || max < num) {
alert(num + ' n\'is not between ' + min + ' and ' + max);
return false;
}
</script>
</head>
<body>
<form>
Value: <input type='text' id="value_one" onBlur="minMax();">
</form>
</body>
</html>
Is it feasible to incorporate a confirm box for numbers larger than 100? Any ideas are welcome!