-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
52 lines (32 loc) · 1.14 KB
/
script.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const label = document.querySelector("label[for='upload_file']");
const upload_form = document.querySelector("#upload_form");
const upload_file = document.querySelector("#upload_file");
const uploaded_image_info = document.querySelector("#uploaded_img");
//handles the uploading of image
upload_file.onchange = function(){
//console.log(this)
const file_item = this.files[0];
const filereader = new FileReader();
filereader.readAsDataURL(file_item)
//get the result
filereader.onload = function(){
// console.log(this.result);
uploaded_image_info.innerHTML = `<img src='${this.result}' width=250>`;
}
}
//end of image upload handling
upload_form.addEventListener("submit", function(e){
e.preventDefault();
if(this.username.value.trim().length == 0 || this.password.value.trim().length == 0){
//
}else{
//process the form
const formData = new FormData(upload_form);
const xhr = new XMLHttpRequest;
xhr.open("POST", "process.php");
xhr.onload = function(){
alert(xhr.response);
}
xhr.send(formData);
}
})