Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $('#submit-button').on('click', function(e) {
- e.preventDefault();
- resetErrors();
- var url = 'http://localhost/arbetsprov/val.php';
- var name1 = $('#name').val();
- var email1 = $('#email').val();
- var phone1 = $('#phone').val();
- var org1 = $('#org').val();
- var adress1 = $('#adress').val();
- //end each
- $.ajax({
- dataType: 'json',
- type: 'POST',
- url: url,
- data: {name: name1,},
- success: function(resp) {
- console.log(resp);
- if (resp === true) {
- //successful validation
- $('form').submit();
- return false;
- } else {
- $.each(resp, function(i, v) {
- console.log(i + " => " + v); // view in console for error messages
- var msg = '<label class="error" for="'+i+'">'+v+'</label>';
- $('input[name="' + i + '"], select[name="' + i + '"]').addClass('inputTxtError').after(msg);
- });
- var keys = Object.keys(resp);
- $('input[name="'+keys[0]+'"]').focus();
- }
- return false;
- },
- error: function() {
- console.log('there was a problem checking the fields');
- }
- });
- return false;
- });
- });
- function resetErrors() {
- $('form input, form select').removeClass('inputTxtError');
- $('label.error').remove();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement