javascript if conditions sample program
Views: 160
Demo
Code
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#btn").click(function() {
console.log("after click the button");
var age = $("#age").val();
console.log("selct age is" + age);
if (age < 0) {
$("#result").html("check your age");
return;
}
var output = '';
if (age >= 0 && age < 10) {
output = 'infant'
} else if (age >= 11 && age <= 17) {
output = 'minor'
} else if (age >= 18 && age <= 50) {
output = 'major'
} else {
output = 'adult'
}
$("#result").html(output);
});
});
</script>
</head>
<body>
Enter age :
<input type="text" name="number" id="age"> </input><br><br>
<button id="btn"> Submit </button>
<p id="result"></p>
</body>
</html>
On By
Navya