-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjscript.js
30 lines (22 loc) · 977 Bytes
/
jscript.js
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
document.getElementById('postForm').addEventListener('submit', function(e) {
e.preventDefault();
const title = document.getElementById('title').value;
const content = document.getElementById('content').value;
const image = document.getElementById('image').files[0];
const video = document.getElementById('video').value;
// Create a new blog post element
const postElement = document.createElement('div');
postElement.classList.add('post');
let postHTML = `<h2>${title}</h2><p>${content}</p>`;
if (image) {
const imageURL = URL.createObjectURL(image);
postHTML += `<img src="${imageURL}" alt="${title}">`;
}
if (video) {
postHTML += `<iframe width="560" height="315" src="${video}" frameborder="0"></iframe>`;
}
postElement.innerHTML = postHTML;
document.getElementById('blogPosts').appendChild(postElement);
// Reset form fields
document.getElementById('postForm').reset();
});