How to set a max value for a text box in JavaScript?
For example, the value must be within 100. No greater value must be entered.
My task, I am using two text boxes where I am inserting marks.
The first text box my marks will be out of 80.
The second will be out of 20.
I am calculating the total of the 1st and 2nd mark and
the result will be in another text box. The mark for the third text box will be 100.
Now, my query is: how to set the maximum value for the values for mark 1 mark 2 and total as 80,20 and 100, respectively.
mark1/80 mark2/20 total/100
qqq 80 20 100
Add
onsubmitto the form and set to a custom function likeonsubmit="return mycheck();".There you can get your textbox using
document.getElementById()and their values with.value. To get a number just dovar thenumber = new Number(document.getElementById('theid').value);.Then do whatever check you need with the number and return true if all it’s OK or false if it isn’t.