Is that all of your code? If so, the function isn't being called. Someone in the comments suggested an input function, but that wouldn't work if you want the number to potentially be multiple digits. Here are two possibilities:
- This would call every time you press enter ("submitting" the form):
html:
<form onsubmit="jsdegree(event)">
<input id="Degree" name="degree" type="number">
</form>
You could also add, between the first <input>
and the closing </form>
tag, a submit button: <input type-"submit">
and then people could also trigger the event by pressing it.
JavaScript:
function jsdegree(event){
event.preventDefault();
var deg = document.getElementById('Degree').value;
if (deg <73 ) {
alert(" your degree is less than required ");
}
}
Note the event.preventDefault()
is important here, otherwise pressing enter will reload the page.
- This would call every time you click away from the input:
html:
<input id="Degree" name="degree" type="number" onchange="jsdegree()">
And your JavaScript could stay the same.