Hi Team
I need help my form is not submitting, but i dont have any errors and want to use bootsrap alerts when form is submitted successfully and required is not displaying.
// html
Code
Student Refund Form
Student Name
Student ID
Course Name
Reason for Refund
Select a reason
Course Cancelled
Schedule Conflict
Personal Reasons
Other
Details
Jayraj ChhayaRank #304 · 8.2K reputationPosted Nov 25, 2024, 8:10 AM EST
Hi Gcobani Mkontwana,
To address the form submission issue and implement Bootstrap alerts, consider the following steps:
JavaScript Validation: Ensure that you have included JavaScript to handle form validation and submission. You can use the
onsubmitevent to validate the form and display alerts. Here’s a simple example:document.getElementById('myform').onsubmit = function(event) { event.preventDefault(); // Prevent default submission if (this.checkValidity()) { // Show success alert document.getElementById('alertMessage').classList.remove('alert-danger'); document.getElementById('alertMessage').classList.add('alert-success'); document.getElementById('alertText').innerText = 'Form submitted successfully!'; document.getElementById('alertMessage').style.display = 'block'; // Optionally, submit the form via AJAX or redirect } else { // Show error alert document.getElementById('alertMessage').classList.remove('alert-success'); document.getElementById('alertMessage').classList.add('alert-danger'); document.getElementById('alertText').innerText = 'Please fill out all required fields.'; document.getElementById('alertMessage').style.display = 'block'; } };Bootstrap Alerts: Ensure you have included Bootstrap CSS and JS in your HTML file for the alerts to function properly.
Required Field Validation: The
requiredattribute is correctly placed in your input fields. Ensure that your browser supports HTML5 validation, or consider using a library like jQuery Validation for enhanced functionality.By implementing these changes, your form should submit correctly, and users will receive appropriate feedback through Bootstrap alerts.