You are on page 1of 15

lectures/6/src/blink.html 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23.

24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. <!-blink.html David J. Malan Computer Science S-75 Harvard Summer School --> <!DOCTYPE html> <html> <head> <script> function blinker() { var blinks = document.getElementsByTagName("blink"); for (var i = 0; i < blinks.length; i++) { if (blinks[i].style.visibility == "hidden") blinks[i].style.visibility = "visible"; else blinks[i].style.visibility = "hidden"; } } window.setInterval(blinker, 500); </script> <title></title> </head> <body> <center> <blink><h1>hello, world</h1></blink> </center> </body> </html>

lectures/6/src/form1.html 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. <!-form1.html A form without client-side validation. David J. Malan Computer Science S-75 Harvard Summer School --> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="process.php" method="get"> Email: <input name="email" type="text"> <br> Password: <input name="password1" type="password"> <br> Password (again): <input name="password2" type="password"> <br> I agree to the terms and conditions: <input name="agreement" type="checkbox"> <br><br> <input type="submit" value="Submit"> </form> </body> </html>

lectures/6/src/form2.html 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. <!-form2.html A form with client-side validation. David J. Malan Computer Science S-75 Harvard Summer School --> <!DOCTYPE html> <html> <head> <script> function validate() { if (document.forms.registration.email.value == "") { alert("You must provide an email adddress."); return false; } else if (document.forms.registration.password1.value == "") { alert("You must provide a password."); return false; } else if (document.forms.registration.password1.value != document.forms.registration.password2.value) { alert("You must provide the same password twice."); return false; } else if (!document.forms.registration.agreement.checked) { alert("You must agree to our terms and conditions."); return false; } return true; } </script> <title></title> </head> <body> <form action="process.php" id="registration" method="get" onsubmit="return validate();">

lectures/6/src/form2.html 49. Email: <input name="email" type="text"> 50. <br> 51. Password: <input name="password1" type="password"> 52. <br> 53. Password (again): <input name="password2" type="password"> 54. <br> 55. I agree to the terms and conditions: <input name="agreement" type="checkbox"> 56. <br><br> 57. <input type="submit" value="Submit"> 58. </form> 59. </body> 60. </html>

lectures/6/src/form3.html 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. <!-form3.html A form with client-side validation demonstrating "with" keyword. David J. Malan Computer Science S-75 Harvard Summer School --> <!DOCTYPE html> <html> <head> <script> function validate() { with (document.forms.registration) { if (email.value == "") { alert("You must provide an email adddress."); return false; } else if (password1.value == "") { alert("You must provide a password."); return false; } else if (password1.value != password2.value) { alert("You must provide the same password twice."); return false; } else if (!agreement.checked) { alert("You must agree to our terms and conditions."); return false; } return true; } } </script> <title></title>

lectures/6/src/form3.html 49. </head> 50. <body> 51. <form action="process.php" method="get" name="registration" onsubmit="return validate();"> 52. Email: <input name="email" type="text"> 53. <br> 54. Password: <input name="password1" type="password"> 55. <br> 56. Password (again): <input name="password2" type="password"> 57. <br> 58. I agree to the terms and conditions: <input name="agreement" type="checkbox"> 59. <br><br> 60. <input type="submit" value="Submit"> 61. </form> 62. </body> 63. </html>

lectures/6/src/form4.html 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. <!-form4.html A form with client-side validation demonstrating "this" keyword. David J. Malan Computer Science S-75 Harvard Summer School --> <!DOCTYPE html> <html> <head> <script> function validate(f) { if (f.email.value == "") { alert("You must provide an email adddress."); return false; } else if (f.password1.value == "") { alert("You must provide a password."); return false; } else if (f.password1.value != f.password2.value) { alert("You must provide the same password twice."); return false; } else if (!f.agreement.checked) { alert("You must agree to our terms and conditions."); return false; } return true; } </script> <title></title> </head> <body> <form action="process.php" method="get" name="registration" onsubmit="return validate(this);">

lectures/6/src/form4.html 49. Email: <input name="email" type="text"> 50. <br> 51. Password: <input name="password1" type="password"> 52. <br> 53. Password (again): <input name="password2" type="password"> 54. <br> 55. I agree to the terms and conditions: <input name="agreement" type="checkbox"> 56. <br><br> 57. <input type="submit" value="Submit"> 58. </form> 59. </body> 60. </html>

lectures/6/src/form5.html 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. <!-form5.html A form with client-side validation demonstrating disabled property. David J. Malan Computer Science S-75 Harvard Summer School --> <!DOCTYPE html> <html> <head> <script> function toggle() { if (document.forms.registration.button.disabled) document.forms.registration.button.disabled = false; else document.forms.registration.button.disabled = true; } function validate() { if (document.forms.registration.email.value == "") { alert("You must provide an email adddress."); return false; } else if (document.forms.registration.password1.value == "") { alert("You must provide a password."); return false; } else if (document.forms.registration.password1.value != document.forms.registration.password2.value) { alert("You must provide the same password twice."); return false; } else if (!document.forms.registration.agreement.checked) { alert("You must agree to our terms and conditions."); return false; }

lectures/6/src/form5.html 49. return true; 50. } 51. 52. </script> 53. <title></title> 54. </head> 55. <body> 56. <form action="process.php" method="get" name="registration" onsubmit="return validate();"> 57. Email: <input name="email" type="text"> 58. <br> 59. Password: <input name="password1" type="password"> 60. <br> 61. Password (again): <input name="password2" type="password"> 62. <br> 63. I agree to the terms and conditions: <input name="agreement" onclick="toggle();" type="checkbox"> 64. <br><br> 65. <input disabled="disabled" name="button" onclick="alert('testing 1 2 3');" type="submit" value="Submit"> 66. </form> 67. </body> 68. </html>

lectures/6/src/form6.html 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. <!-form6.html A form with client-side validation demonstrating inline JavaScript. David J. Malan Computer Science S-75 Harvard Summer School --> <!DOCTYPE html> <html> <head> <script> function validate() { if (document.forms.registration.email.value == "") { alert("You must provide an email adddress."); return false; } else if (document.forms.registration.password1.value == "") { alert("You must provide a password."); return false; } else if (document.forms.registration.password1.value != document.forms.registration.password2.value) { alert("You must provide the same password twice."); return false; } else if (!document.forms.registration.agreement.checked) { alert("You must agree to our terms and conditions."); return false; } return true; } </script> <title></title> </head> <body> <form action="process.php" method="get" name="registration" onsubmit="return validate();">

lectures/6/src/form6.html 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. Email: <input name="email" type="text"> <br> Password: <input name="password1" type="password"> <br> Password (again): <input name="password2" type="password"> <br> I agree to the terms and conditions: <input name="agreement" onclick="document.forms.registration.button.disabled = !document.forms.registration.button.disabled;" type="checkbox"> <br><br> <input disabled="disabled" name="button" type="submit" value="Submit"> </form> </body> </html>

lectures/6/src/form7.html 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. <!-form7.html A form with client-side validation demonstrating regular expressions. David J. Malan Computer Science S-75 Harvard Summer School --> <!DOCTYPE html> <html> <head> <script> function validate() { if (!document.forms.registration.email.value.match(/.+@.+\.edu$/)) { alert("You must provide a .edu email adddress."); return false; } else if (document.forms.registration.password1.value == "") { alert("You must provide a password."); return false; } else if (document.forms.registration.password1.value != document.forms.registration.password2.value) { alert("You must provide the same password twice."); return false; } else if (!document.forms.registration.agreement.checked) { alert("You must agree to our terms and conditions."); return false; } return true; } </script> <title></title> </head> <body> <form action="process.php" method="get" name="registration" onsubmit="return validate();">

lectures/6/src/form7.html 49. Email: <input name="email" type="text"> 50. <br> 51. Password: <input name="password1" type="password"> 52. <br> 53. Password (again): <input name="password2" type="password"> 54. <br> 55. I agree to the terms and conditions: <input name="agreement" type="checkbox"> 56. <br><br> 57. <input type="submit" value="Submit"> 58. </form> 59. </body> 60. </html>

lectures/6/src/process.php 1. <!-- quick and dirty dump of HTTP request --> 2. 3. <pre> 4. <? print_r($_REQUEST); ?> 5. </pre>

You might also like