Advertisement
Guest User

Untitled

a guest
Sep 14th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 4.50 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4.  
  5. <title>JavaScript Comment Board</title>
  6.  
  7. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  8.  
  9. </head>
  10.  
  11. <body>
  12.  
  13. <div class="container">
  14.  
  15. <div class="pb-2 mt-4 mb-2 border-bottom">
  16.     <h1>My Fake Blog</h1>
  17. </div>
  18.  
  19. <div class="row col-md-8 col-md-offset-2">
  20.  
  21. <h2>Post About Thing</h2>
  22.  
  23. <p>
  24. This is a wall of text. This is a wall of text. This is a wall of text.
  25. This is a wall of text. This is a wall of text. This is a wall of text.
  26. This is a wall of text. This is a wall of text. This is a wall of text.
  27. This is a wall of text. This is a wall of text. This is a wall of text.
  28. This is a wall of text. This is a wall of text. This is a wall of text.
  29. This is a wall of text. This is a wall of text. This is a wall of text.
  30. This is a wall of text. This is a wall of text. This is a wall of text.
  31. This is a wall of text. This is a wall of text. This is a wall of text.
  32. This is a wall of text. This is a wall of text. This is a wall of text.
  33. This is a wall of text. This is a wall of text. This is a wall of text.
  34. This is a wall of text. This is a wall of text. This is a wall of text.
  35. This is a wall of text. This is a wall of text. This is a wall of text.
  36. This is a wall of text. This is a wall of text. This is a wall of text.
  37. This is a wall of text. This is a wall of text. This is a wall of text.
  38. This is a wall of text. This is a wall of text. This is a wall of text.
  39. This is a wall of text. This is a wall of text. This is a wall of text.
  40. This is a wall of text. This is a wall of text. This is a wall of text.
  41. This is a wall of text. This is a wall of text. This is a wall of text.
  42. This is a wall of text. This is a wall of text. This is a wall of text.
  43. This is a wall of text. This is a wall of text. This is a wall of text.
  44. This is a wall of text. This is a wall of text. This is a wall of text.
  45. This is a wall of text. This is a wall of text. This is a wall of text.
  46. This is a wall of text. This is a wall of text. This is a wall of text.
  47. This is a wall of text. This is a wall of text. This is a wall of text.
  48. This is a wall of text. This is a wall of text. This is a wall of text.
  49. This is a wall of text. This is a wall of text. This is a wall of text.
  50. This is a wall of text. This is a wall of text. This is a wall of text.
  51. This is a wall of text. This is a wall of text. This is a wall of text.
  52. This is a wall of text. This is a wall of text. This is a wall of text.
  53. </p>
  54.  
  55. <div class="card w-100">
  56.     <h3 class="card-header">Add a comment</h3>
  57.     <div class="card-body">
  58.         <form>
  59.             <div class="form-group">
  60.                 <input id="comment_name" type="textbox" class="form-control" placeholder="Name"/>
  61.             </div>
  62.             <div class="form-group">
  63.                 <textarea id="comment_text" rows="4" cols="60" class="form-control" placeholder="Comment"></textarea>
  64.             </div>
  65.             <div class="form-group">
  66.                 <button id="comment_submit_button" class="btn btn-primary" >Post</button>
  67.             </div>
  68.         </form>
  69.     </div>
  70. </div>
  71.  
  72. <div id="test" class="card w-100 mt-3">
  73.     <div class="card-header">
  74.         <div class="row">
  75.             <div class="col-md-11">
  76.                 <h4 id="comment_board-userName">etomai</h4>
  77.             </div>
  78.             <div class="col-md-1">
  79.                 <button class="delete_btn" class="btn">X</button>
  80.             </div>
  81.         </div>
  82.     </div>
  83.  
  84.     <div class="card-body">
  85.         <p id="comment_board-userText">This is my comment.  I think the post is too long.</p>
  86.     </div>
  87.     <br>
  88. </div>
  89.  
  90. <div></div>
  91.  
  92. </div>
  93.  
  94. <script src="http://code.jquery.com/jquery.min.js"></script>
  95. <script src="comment.js"></script>
  96. <script src="js_moment.js"></script>
  97.  
  98. </script>
  99.  
  100. </body>
  101.  
  102. </html>
  103.  
  104. ////////////////////////////////////////// jquery code below ////////////////////////////////////////////
  105.  
  106. $("#comment_submit_button").click(function()
  107. {
  108.    
  109.     comment_name = $("#comment_name").val();
  110.     comment_text = $("#comment_text").val();
  111.     comment_date = moment().format("l");
  112.    
  113.     if(!/^[a-zA-Z0-9]+/.test(comment_name))
  114.     {
  115.         comment_name = "Error_User-Violation"
  116.        
  117.     }
  118.     if(!comment_text.trim())
  119.     {
  120.         comment_text = "Error_Text_Violation"
  121.     }
  122.    
  123.     comment_template = $("#test").clone();
  124.  
  125.     comment_template.find("#comment_board-userName").text(comment_name).append( "<br>"  + comment_date);
  126.     comment_template.find("#comment_board-userText").text(comment_text);
  127.     comment_template.insertBefore("#test");
  128.  
  129.     return false //equals like system("pause") in c++
  130.  
  131. })
  132.  
  133. $(document).on('click', '.delete_btn' , function()
  134. {
  135.     console.log("hu")
  136.     $(this).find("#test").remove();
  137.     console.log("nothing happen")
  138.  
  139.    
  140. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement