Advertisement
KodingKid

Javascript input - First and Second name and age + limits and submitting processing!

Apr 29th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var firstName = document.getElementById("name1").value; //creates first name variable
  2. var age = document.getElementById("age").value; //creates age variable
  3. var secondName = document.getElementById("name2").value; //creates second name variable
  4. Submitted = "true"; //submits data...
  5. if (firstName.length > 15) { //unless if the name is longer than 15 characters
  6.     alert("The name must have no more than 15 characters!") //for which you'll get an alert
  7.     Submitted = "false"; //and your data won't be submitted
  8. }
  9. if (isNaN(age) || age < 10 || age > 120) { //or your age is below 10 or over 120
  10.     alert("The age must be between numbers 10 and 120!") //for which you'll get an alert
  11.     Submitted = "false"; //and your data won't be submitted
  12. }
  13. if (secondName.length > 15) //unless if the name is longer than 15 characters
  14.     alert("The name must have no more than 15 characters!") //for which you'll get an alert
  15.     Submitted = "false"; //and your data won't be submitted (again lol)
  16. }
  17. if (Submitted == "false") {  //if it isn't submitted...
  18.     return false; //it doesn't do anything
  19. }
  20. //the end...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement