-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresultado.html
124 lines (106 loc) · 4.87 KB
/
resultado.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Resultado</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body onload="loader()">
<div class="row">
<fieldset>
<legend>
<h2> Retorno dados</h2>
</legend>
<label for="name">Nome</label>
<input type="text" disabled name="nome" id="nome" placeholder="Digite seu nome completo">
<div class="row">
<label for="dataNas">Data de Nascimento</label>
<input type="text" disabled name="dataNas" id="dataNas" placeholder="Digite sua data de nascimento">
</div>
<fieldset>
<legend>
<h3>Retorno Endereço</h3>
</legend>
<div class="row">
<label for="cep">Cep</label>
<input type="text" disabled name="cep" id="cep" placeholder="Digite seu CEP">
</div>
<div class="row">
<label for="rua">Rua</label>
<input type="text" disabled name="rua" id="rua" placeholder="Digite o nome da rua">
</div>
<div class="row">
<label for="num">Número</label>
<input type="number" disabled name="num" id="num" placeholder="Digite o numero da casa">
</div>
</fieldset>
</fieldset>
</div>
</form>
<script>
var loader = function () {
var array = [];
array = getAllUrlParams(location.href);
// console.log(new Date(array.datanas));
document.getElementById("nome").value = array.nome;
document.getElementById("dataNas").value = array.datanas;
document.getElementById("cep").value = array.cep;
document.getElementById("rua").value = array.rua;
document.getElementById("num").value = array.num;
}
function getAllUrlParams(url) {
// get query string from url (optional) or window
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
// we'll store the parameters here
var obj = {};
// if query string exists
if (queryString) {
// stuff after # is not part of query string, so get rid of it
queryString = queryString.split('#')[0];
// split our query string into its component parts
var arr = queryString.split('&');
for (var i = 0; i < arr.length; i++) {
// separate the keys and the values
var a = arr[i].split('=');
// set parameter name and value (use 'true' if empty)
var paramName = a[0];
var paramValue = typeof (a[1]) === 'undefined' ? true : a[1];
// (optional) keep case consistent
paramName = paramName.toLowerCase();
if (typeof paramValue === 'string') paramValue = paramValue.toLowerCase();
// if the paramName ends with square brackets, e.g. colors[] or colors[2]
if (paramName.match(/\[(\d+)?\]$/)) {
// create key if it doesn't exist
var key = paramName.replace(/\[(\d+)?\]/, '');
if (!obj[key]) obj[key] = [];
// if it's an indexed array e.g. colors[2]
if (paramName.match(/\[\d+\]$/)) {
// get the index value and add the entry at the appropriate position
var index = /\[(\d+)\]/.exec(paramName)[1];
obj[key][index] = paramValue;
} else {
// otherwise add the value to the end of the array
obj[key].push(paramValue);
}
} else {
// we're dealing with a string
if (!obj[paramName]) {
// if it doesn't exist, create property
obj[paramName] = paramValue;
} else if (obj[paramName] && typeof obj[paramName] === 'string') {
// if property does exist and it's a string, convert it to an array
obj[paramName] = [obj[paramName]];
obj[paramName].push(paramValue);
} else {
// otherwise add the property
obj[paramName].push(paramValue);
}
}
}
}
return obj;
}
</script>
</body>
</html>