Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>JSP Page</title>
  6. <script src="newjavascript.js"></script>
  7. </head>
  8. <body>
  9. Name: <input type="text" value="" id="t1"><br>
  10. Age: <input type="text" value="" id="t2"><br>
  11. Rollno: <input type="text" value="" id="t3"><br>
  12. Address: <input type="text" value="" id="t4"><br>
  13. <div id="er" style="color: red;"></div>
  14. <input type="submit" value="Submit" onclick="validation()">
  15. </body>
  16. </html>
  17.  
  18. var st_roll_no="";
  19.  
  20. function validation()
  21. {
  22. if (document.getElementById("t1").value.replace(/^s+|s+$/g, "") === "")
  23. {
  24. document.getElementById("er").innerHTML = "please select name";
  25. }
  26. else if (document.getElementById("t2").value.replace(/^s+|s+$/g, "") === "")
  27. {
  28. document.getElementById("er").innerHTML = "please select age";
  29. }
  30. else if (document.getElementById("t3").value.replace(/^s+|s+$/g, "") != "")
  31. {
  32. fetch_rollno(document.getElementById("t3").value);
  33. alert("After fetching the result is "+st_roll_no);
  34. }
  35. else if (st_roll_no.replace(/^s+|s+$/g, "") === "found")
  36. {
  37. document.getElementById("er").innerHTML = "Please enter address";
  38. }
  39. else if (document.getElementById("t4").value.replace(/^s+|s+$/g, "") === "")
  40. {
  41. document.getElementById("er").innerHTML = "Please enter address";
  42. }
  43. else
  44. {
  45. alert("success");
  46. }
  47. }
  48.  
  49. function fetch_rollno(rollno)
  50. {
  51. $.ajax({
  52. type: "POST",
  53. url: 'validate_rollno',
  54. data: {rollno: rollno},
  55. success: function(result)
  56. {
  57. alert("result from database is "+result);
  58. if (result == "found")
  59. {
  60. alert("if");
  61. st_roll_no="found";
  62. alert(st_roll_no);
  63.  
  64. }
  65. else
  66. {
  67. alert("else");
  68. st_roll_no="notfound";
  69. alert(st_roll_no);
  70.  
  71. }
  72.  
  73. }
  74. });
  75. }
  76.  
  77. alert("After fetching the result is "+st_roll_no);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement