-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm.html
More file actions
148 lines (137 loc) · 4.32 KB
/
Form.html
File metadata and controls
148 lines (137 loc) · 4.32 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html>
<head>
<title>FORM</title>
<style type="text/css">
label{
text-align:left;
padding-right:20px;
display:inline-block;
min-width:150px;
}
button {
padding: 10px 20px;
background-color: dodgerblue;
border: 1px solid #ddd;
color: white;
}
</style>
</head>
<body>
<div id="result">
<form method="post" action="" id="formToSave">
<h2>GROOTAN TEST</h2>
<h3>Round 2</h3>
<label>Name</label>
<input type="text" name="username" id="un" required>
<br>
<br>
<label>Age</label>
<input type="text" name="age" id="age" required>
<br>
<br>
<label>Country</label>
<select name="country" id="country" required>
<option value="India">India</option>
<option value="Sri Lanka">Kenya</option>
<option value="Australia">Australia</option>
</select>
<br>
<br>
<label>DOB</label>
<input type="date" name="birth" id="dob" required>
<br>
<br>
<label>Gender</label>
<input type="radio" name="gender" id="gender" value="Male">Male
<input type="radio" name="gender" id="gender" value="Female">Female
<input type="radio" name="gender" id="gender" value="Others">Others
<br>
<br>
<label>Languages Known</label>
<select name="Languages" id="languages" required>
<option value="Java">Java</option>
<option value="Python">Python</option>
<option value="Ruby">Ruby</option>
</select>
<br>
<br>
<label>Favourite Color</label>
<input type="color" id="fc" name="favcolor" value="#ff0000" required>
<br>
<br>
<label>Upload Photograph</label>
<input type="file" name="img" accept="image/png" id="img" required>
<br>
<br>
<label>Email id</label>
<input type="text" name="email_id" id="email" required>
<br>
<br>
<label>Start Time</label>
<input type="time" name="time" id="st" required>
<br>
<br>
<label>Website Address</label>
<input type="text" name="web_address" id="wa" required>
<br>
<br>
<label>CGPA</label>
<input type="range" id="cgpa" name="cgpa" min="1" max="10" value="5" required>
<br>
<br>
<input type="button" name="submit" value="SUBMIT" onclick="saveFile()">
</div>
</form>
</body>
<script>
let saveFile = () => {
const name = document.getElementById('un');
const age = document.getElementById('age');
const country= document.getElementById('country');
const DOB= document.getElementById('dob');
const gender= document.getElementById('gender');
const languages= document.getElementById('languages');
const favColor = document.getElementById('fc');
const email = document.getElementById('email');
const start= document.getElementById('st');
const webAddress= document.getElementById('wa');
const cgpa= document.getElementById('cgpa');
const img = document.getElementById('img');
let data =
'\r Name: ' + name.value + ' \r\n ' +
'Age: ' +age.value + ' \r\n ' +
'DOB: ' + DOB.value + ' \r\n ' +
'Country: ' + country.value + ' \r\n ' +
'Gender: ' + gender.value + '\r\n' +
'Favourite Color: ' + favColor.value + '\r\n' +
'Email ID: ' + email.value + '\r\n' +
'Start time: ' + start.value + '\r\n' +
'Web Address: ' + webAddress.value + '\r\n' +
'CGPA: ' + cgpa.value + '\r\n' +
'Languages:'+ languages.value ;
const textToBLOB = new Blob([data], { type: 'text/plain' });
const sFileName = 'formData.txt';
var link = document.createElement('a');
link.download = 'Download.jpg';
let newLink = document.createElement("a");
newLink.download = sFileName;
console.log('entering');
if (window.webkitURL != null) {
newLink.href = window.webkitURL.createObjectURL(textToBLOB);
link.href = img;
console.log('entering url')
}
else {
newLink.href = window.URL.createObjectURL(textToBLOB);
link.href = img;
newLink.style.display = "none";
document.body.appendChild(newLink);
document.body.appendChild(link);
console.log('entering ytyh')
}
newLink.click();
link.click();
}
</script>
</html>