HTML/JAVASCRIPT Validating Inputs (using Workbench)
Had a question: How do you validate inputs? (I do pay attention to my comments!) A good question (and gives me the opportunity to show off Workbench with HTML/JavaScript)!
First one wants to use the following code:
?>
<script language="javascript">
function validate(id,from,to){
? let x=document.getElementById(id);
? alert("Working with " + x.value + " from " + from + " to "
+ to);
? if(x.value >= from && x.value <= to) {
??? alert("Works!");
? }
? else{
??? alert("Gotta be " + from + "<= " + x.value + " <= " + to);
? }
}
</script>
<h1>Javascript Validation</h1>
<form>
1-10<input type="text" id="a" onblur='validate("a", 1, 10)'><br>
11-20<input type="text" id="b" onblur='validate("b", 11, 20)'><br>
21-30<input type="text" id="c" onblur='validate("c", 21, 30)'><br>
<input type="submit" value="Go">
</form>
You'll want the first line (?>) cuz it is closing a PHP area (not using PHP!) just plain ole HTML/JavaScript with this one! We prep a JavaScript function definition validate which determines if input falls between a from and to value. Then we intro a little form so we can play around on the screen.
Notice the inputs have a onblur event capture feeding it to validate. If you click inside, type a number, then click out side the input, you introduce the creation of an event - onblur, which you can capture and can JavaScript to.
and by placing 2 into the second:
and yea, that don't work!