Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. $(document).ready(function() {
  2. $('#submit-button').on('click', function(e) {
  3. e.preventDefault();
  4. resetErrors();
  5. var url = 'http://localhost/arbetsprov/val.php';
  6. var name1 = $('#name').val();
  7. var email1 = $('#email').val();
  8. var phone1 = $('#phone').val();
  9. var org1 = $('#org').val();
  10. var adress1 = $('#adress').val();
  11. //end each
  12. $.ajax({
  13. dataType: 'json',
  14. type: 'POST',
  15. url: url,
  16. data: {name: name1,},
  17. success: function(resp) {
  18. console.log(resp);
  19. if (resp === true) {
  20. //successful validation
  21. $('form').submit();
  22. return false;
  23. } else {
  24. $.each(resp, function(i, v) {
  25. console.log(i + " => " + v); // view in console for error messages
  26. var msg = '<label class="error" for="'+i+'">'+v+'</label>';
  27. $('input[name="' + i + '"], select[name="' + i + '"]').addClass('inputTxtError').after(msg);
  28. });
  29. var keys = Object.keys(resp);
  30. $('input[name="'+keys[0]+'"]').focus();
  31. }
  32. return false;
  33. },
  34. error: function() {
  35. console.log('there was a problem checking the fields');
  36. }
  37. });
  38. return false;
  39. });
  40. });
  41. function resetErrors() {
  42. $('form input, form select').removeClass('inputTxtError');
  43. $('label.error').remove();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement