-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposting.js
82 lines (69 loc) · 2.12 KB
/
posting.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
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
// submit post form
function submitpost(){
var jhuEmail=document.Form.itememail.value;
if (!(jhuEmail.includes("@jhu.edu"))){
document.Form.itememail.value="";
document.Form.itememail.focus();
alert("wrong email");
return false;
}
if(!checkprice())return false;
if(!checkplace())return false;
var phone=document.Form.itemphone.value;
if(isNaN(phone))return false;
alert("Succseeful");
return true;
}
// validation
function checkprice(){
var price=document.Form.itemprice.value;
if(isNaN(price)){
alert ("invalid price");
document.Form.itemprice.focus();
return false;
}else if(price<=0){
alert ("invalid price");
document.Form.itemprice.focus();
return false;
}
return true;
}
function checkplace(){
var place=document.Form.itemplace.value;
if(place==3){
var place2=document.Form.otherplace.value;
if(place2==""){
alert ("other place required");
document.Form.otherplace.focus();
return false;
}
}
return true;
}
//description textarea auto expand
function text_extend(a,b) {
a.style.height="190px";
var aa=a.scrollHeight+b;
a.style.height=aa+"px";
}
//allow more picture and display immediately
function showimg(a0){
for(var i=0; i<a0.files.length; i++){
var img1=new FileReader();
img1.readAsDataURL(a0.files[i]);
img1.onload=function(){
var node1= document.createElement("img");
node1.src=this.result;
preshowimage.appendChild(node1);
};
}
preshowinput.insertBefore(a0,preshowinput.childNodes[0].nextSibling);
preshowinput.childNodes[0].innerHTML="<span></span><input type='file' name='picture[]' accept='image/*' multiple oninput='showimg(this)' />";
//console.log(preshowinput.childNodes[0].innerHTML);
}
//reset: description textarea && picture show
function text_shrink(){
mess1.style.height="200px";
preshowimage.innerHTML="";
preshowinput.innerHTML='<label><span></span><input type="file" name="picture[]" accept="image/*" multiple oninput="showimg(this)" /></label>';
}