Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. "use strict";
  2. var CharPack = CharPack || {};
  3. (function($) {
  4. CharPack.add = function () {
  5. //Validate the character name
  6. var newCharName = $("#charName").val().trim();
  7. if (newCharName == "") {
  8. alert("Sorry, you must provide a character name.");
  9. return;
  10. }
  11. //Validate the character quote
  12. var newCharQuote = $("#charQuote").val().trim();
  13. if (newCharQuote == "") {
  14. alert("Sorry, you must provide a character quote.");
  15. return;
  16. }
  17. //Validate the special move
  18. var newCharMove = $("#charMove").val().trim();
  19. if (newCharMove == "") {
  20. alert("Sorry, you must provide a special move.");
  21. return;
  22. }
  23. //Data Ok
  24. //Add a new record
  25. //find the highest ID
  26. var highestId = CharPack.packDb().max("id");
  27. //New char's ID is one more
  28. var newCharId = highestId + 1;
  29. //Create a new object.
  30. var newChar = {
  31. id: newCharId,
  32. name: newCharName,
  33. quote: newCharQuote,
  34. specialmove: newCharMove
  35. };
  36. //Add the new item.
  37. CharPack.packDb.insert(newChar);
  38. //Go to list page.
  39. window.location.href = "index.html";
  40. };
  41. //Cancel the query
  42. CharPack.baleet = function(){
  43. if ( confirm("Are you sure?") ) {
  44. window.location.href = "index.html";
  45. }
  46. };
  47. $(document).ready(function () {
  48. //Load the navbar from the library.
  49. $("#navbar").load("library/includes/navbar.html");
  50. //Load the footer from the library.
  51. $("#footer").load("library/includes/footer.html");
  52. });
  53. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement