Repository navigation
Expand file tree
/
Copy pathscript (2).js
More file actions
127 lines (110 loc) · 3.82 KB
/
Copy pathscript (2).js
File metadata and controls
127 lines (110 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
$(document).ready(function() {
// Form validation and submission
$('#registrationForm').on('submit', function(e) {
e.preventDefault();
// Validate form
if (!validateForm()) {
return false;
}
// Show loading state
const submitBtn = $('.btn-submit');
const originalText = submitBtn.text();
submitBtn.text('Submitting...').addClass('loading');
// Get form data
const formData = $(this).serialize();
// Submit via AJAX to PHP
$.ajax({
url: 'process.php',
type: 'POST',
data: formData,
dataType: 'json',
success: function(response) {
if (response.success) {
// Display results
displayResults(response.data);
} else {
alert('Error: ' + response.message);
submitBtn.text(originalText).removeClass('loading');
}
},
error: function(xhr, status, error) {
// For demo purposes, if PHP is not available, display form data
console.log('PHP not available, displaying form data directly');
const data = getFormData();
displayResults(data);
},
complete: function() {
submitBtn.text(originalText).removeClass('loading');
}
});
});
// Form validation function
function validateForm() {
let isValid = true;
// Validate phone number
const phone = $('#phone').val();
if (!/^\d{10}$/.test(phone)) {
alert('Please enter a valid 10-digit phone number');
$('#phone').focus();
return false;
}
// Validate email
const email = $('#email').val();
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
alert('Please enter a valid email address');
$('#email').focus();
return false;
}
return isValid;
}
// Get form data as object
function getFormData() {
return {
fullName: $('#fullName').val(),
email: $('#email').val(),
phone: $('#phone').val(),
dob: $('#dob').val(),
address: $('#address').val(),
course: $('#course').val()
};
}
// Display results
function displayResults(data) {
let resultHTML = '';
const labels = {
fullName: 'Full Name',
email: 'Email Address',
phone: 'Phone Number',
address: 'Address',
course: 'Course Applied For'
};
for (let key in data) {
if (data.hasOwnProperty(key) && labels[key]) {
resultHTML += `
<div class="result-item">
<span class="result-label">${labels[key]}:</span>
<span class="result-value">${data[key]}</span>
</div>
`;
}
}
$('#resultContent').html(resultHTML);
// Animate transition
$('#formContainer').fadeOut(300, function() {
$('#resultContainer').fadeIn(300);
});
// Scroll to top
$('html, body').animate({ scrollTop: 0 }, 300);
}
// Phone number formatting
$('#phone').on('input', function() {
this.value = this.value.replace(/[^0-9]/g, '');
if (this.value.length > 10) {
this.value = this.value.slice(0, 10);
}
});
// Prevent future dates in DOB
const today = new Date().toISOString().split('T')[0];
$('#dob').attr('max', today);
});