diff --git a/assets/css/style.css b/assets/css/style.css index 380dfd7..e3aba53 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -2051,4 +2051,86 @@ textarea.input-field { left: 0; } +} +#blog-section { + width: 50%; + margin: 50px auto; + background-color: white; + padding: 20px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + border-radius: 8px; +} + +h2, h3 { + text-align: center; + color: white; + +} + +.form-group { + margin-bottom: 15px; +} + +label { + display: block; + margin-bottom: 5px; + color: #555; +} + +input, textarea { + width: 100%; + padding: 10px; + border: 1px solid #ccc; + border-radius: 4px; + font-size: 1rem; +} + +button { + display: block; + width: 100%; + padding: 10px; + background-color: #007bff; + color: white; + border: none; + border-radius: 4px; + font-size: 1rem; + cursor: pointer; +} + +button:hover { + background-color: #0056b3; +} + +.error-message { + color: red; + font-size: 0.875rem; +} + +.success-message { + color: green; + text-align: center; + font-size: 1rem; + display: none; +} + +#blogList { + margin-top: 20px; +} + +.blog-entry { + background: #444444; + padding: 15px; + border-radius: 6px; + margin-bottom: 10px; + color: white; + display: grid; + padding-left: 100px; +} + +.blog-entry h4, .blog-entry p { + margin: 0 0 10px; +} +.blogs{ + color: white; + background: #444444; } \ No newline at end of file diff --git a/assets/js/script.js b/assets/js/script.js index 6403e32..77431d9 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -1,3 +1,70 @@ +document.getElementById("blogForm").addEventListener("submit", function(event) { + event.preventDefault(); + + const name = document.getElementById("name").value; + const email = document.getElementById("email").value; + const description = document.getElementById("description").value; + + const isValid = validateForm(name, email, description); + + if (isValid) { + addBlogEntry(name, email, description); + + document.getElementById("successMessage").textContent = "Blog submitted successfully!"; + document.getElementById("successMessage").style.display = "block"; + + document.getElementById("blogForm").reset(); + + setTimeout(() => { + document.getElementById("successMessage").style.display = "none"; + }, 2700); + } else { + alert("Error: Something is wrong!!"); + } +}); + +function validateForm(name, email, description) { + let isCorrect = true; + + if (name.trim() === "") { + document.getElementById("nameError").textContent = "Name is required"; + isCorrect = false; + } + + if (!validateEmail(email)) { + document.getElementById("emailError").textContent = "Please enter a valid email"; + isCorrect = false; + } + + if (description.trim() === "") { + document.getElementById("descriptionError").textContent = "Description is required"; + isCorrect = false; + } + + return isCorrect; +} +// adding the entries and appending it in the div... +function addBlogEntry(name, email, description) { + const blogList = document.getElementById("blogList"); + + const blogEntry = document.createElement("div"); + blogEntry.classList.add("blog-entry"); + + + blogEntry.innerHTML = ` +
Description: ${description}
+ `; + + + blogList.appendChild(blogEntry); +} + +function validateEmail(email) { + const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return re.test(email); +} + /** * PRELOAD diff --git a/index.html b/index.html index e97ba51..e469f68 100644 --- a/index.html +++ b/index.html @@ -1178,6 +1178,33 @@