Skip to content

Instantly share code, notes, and snippets.

@ryanorsinger
Created October 11, 2014 15:44
Show Gist options
  • Save ryanorsinger/177ca51642d1bac231f0 to your computer and use it in GitHub Desktop.
Save ryanorsinger/177ca51642d1bac231f0 to your computer and use it in GitHub Desktop.
<p>Please input a number between 1 and 10:</p>
<input id="numb" type="text">
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
<script id="jsbin-javascript">
function myFunction() {
var x, text;
// Get the value of input field with id="numb"
x = document.getElementById("numb").value;
// If x is Not a Number or less than one or greater than 10
if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Input OK";
}
document.getElementById("demo").innerHTML = text;
}
</script>
<script id="jsbin-source-html" type="text/html"><p>Please input a number between 1 and 10:</p>
<input id="numb" type="text">
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
</script>
<script id="jsbin-source-javascript" type="text/javascript">function myFunction() {
var x, text;
// Get the value of input field with id="numb"
x = document.getElementById("numb").value;
// If x is Not a Number or less than one or greater than 10
if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Input OK";
}
document.getElementById("demo").innerHTML = text;
}</script>
function myFunction() {
var x, text;
// Get the value of input field with id="numb"
x = document.getElementById("numb").value;
// If x is Not a Number or less than one or greater than 10
if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Input OK";
}
document.getElementById("demo").innerHTML = text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment